Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): use HttpError across fetchers

justin02e6ad988575
diff --git a/apps/web/src/fetchers/activity/create-activity.ts b/apps/web/src/fetchers/activity/create-activity.ts
index 045371bd0..50d40feb4 100644
--- a/apps/web/src/fetchers/activity/create-activity.ts
+++ b/apps/web/src/fetchers/activity/create-activity.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateActivityRequest = InferRequestType<
(typeof client)["activity"]["comment"]["$post"]
@@ -14,8 +15,7 @@ async function createActivity({ taskId, comment }: CreateActivityRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/billing/create-checkout.ts b/apps/web/src/fetchers/billing/create-checkout.ts
index e96a69a42..a348fdbe0 100644
--- a/apps/web/src/fetchers/billing/create-checkout.ts
+++ b/apps/web/src/fetchers/billing/create-checkout.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type BillingPlan = "personal" | "team";
export type BillingInterval = "monthly" | "annual";
@@ -14,8 +15,7 @@ export async function createBillingCheckout(input: {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
@@ -27,8 +27,7 @@ export async function createBillingPortal(workspaceId: string) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/billing/get-billing.ts b/apps/web/src/fetchers/billing/get-billing.ts
index 207247c29..4144b8e2c 100644
--- a/apps/web/src/fetchers/billing/get-billing.ts
+++ b/apps/web/src/fetchers/billing/get-billing.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferResponseType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetBillingResponse = InferResponseType<
(typeof client)["billing"][":workspaceId"]["$get"],
@@ -12,8 +13,7 @@ export async function getBilling(workspaceId: string) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/column/create-column.ts b/apps/web/src/fetchers/column/create-column.ts
index e8d2458ec..d24c03eba 100644
--- a/apps/web/src/fetchers/column/create-column.ts
+++ b/apps/web/src/fetchers/column/create-column.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function createColumn(
projectId: string,
data: { name: string; icon?: string; color?: string; isFinal?: boolean },
@@ -10,8 +12,7 @@ async function createColumn(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/column/delete-column.ts b/apps/web/src/fetchers/column/delete-column.ts
index ae683a01b..fa03be05c 100644
--- a/apps/web/src/fetchers/column/delete-column.ts
+++ b/apps/web/src/fetchers/column/delete-column.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteColumn(id: string) {
const response = await client.column[":id"].$delete({
param: { id },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/column/get-columns.ts b/apps/web/src/fetchers/column/get-columns.ts
index 1b878759d..fbd7014fb 100644
--- a/apps/web/src/fetchers/column/get-columns.ts
+++ b/apps/web/src/fetchers/column/get-columns.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getColumns(projectId: string) {
const response = await client.column[":projectId"].$get({
param: { projectId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/column/reorder-columns.ts b/apps/web/src/fetchers/column/reorder-columns.ts
index ab35a7252..c32554f40 100644
--- a/apps/web/src/fetchers/column/reorder-columns.ts
+++ b/apps/web/src/fetchers/column/reorder-columns.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function reorderColumns(
projectId: string,
columns: Array<{ id: string; position: number }>,
@@ -10,8 +12,7 @@ async function reorderColumns(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/column/update-column.ts b/apps/web/src/fetchers/column/update-column.ts
index 64f699710..cfad8476a 100644
--- a/apps/web/src/fetchers/column/update-column.ts
+++ b/apps/web/src/fetchers/column/update-column.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function updateColumn(
id: string,
data: {
@@ -15,8 +17,7 @@ async function updateColumn(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/comment/create-comment.ts b/apps/web/src/fetchers/comment/create-comment.ts
index e48cf13ca..97654941a 100644
--- a/apps/web/src/fetchers/comment/create-comment.ts
+++ b/apps/web/src/fetchers/comment/create-comment.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateCommentRequest = InferRequestType<
(typeof client)["activity"]["comment"]["$post"]
@@ -14,8 +15,7 @@ async function createComment({ taskId, comment }: CreateCommentRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/comment/delete-comment.ts b/apps/web/src/fetchers/comment/delete-comment.ts
index ca01fdc23..fe1f20383 100644
--- a/apps/web/src/fetchers/comment/delete-comment.ts
+++ b/apps/web/src/fetchers/comment/delete-comment.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type DeleteCommentRequest = InferRequestType<
(typeof client)["activity"]["comment"]["$delete"]
@@ -11,8 +12,7 @@ async function deleteComment({ activityId }: DeleteCommentRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/comment/update-comment.ts b/apps/web/src/fetchers/comment/update-comment.ts
index e9344b53a..2e53b23ed 100644
--- a/apps/web/src/fetchers/comment/update-comment.ts
+++ b/apps/web/src/fetchers/comment/update-comment.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type UpdateCommentRequest = InferRequestType<
(typeof client)["activity"]["comment"]["$put"]
@@ -14,8 +15,7 @@ async function updateComment({ activityId, comment }: UpdateCommentRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/config/get-config.ts b/apps/web/src/fetchers/config/get-config.ts
index 16f777a97..858cafc56 100644
--- a/apps/web/src/fetchers/config/get-config.ts
+++ b/apps/web/src/fetchers/config/get-config.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferResponseType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetConfigResponse = InferResponseType<
(typeof client)["config"]["$get"],
@@ -10,8 +11,7 @@ export async function getConfig() {
const response = await client.config.$get();
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/custom-field/create-custom-field.ts b/apps/web/src/fetchers/custom-field/create-custom-field.ts
index ef80632bf..d926170f0 100644
--- a/apps/web/src/fetchers/custom-field/create-custom-field.ts
+++ b/apps/web/src/fetchers/custom-field/create-custom-field.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateCustomFieldRequest = InferRequestType<
(typeof client)["custom-field"]["$post"]
@@ -25,8 +26,7 @@ async function createCustomField({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/delete-custom-field.ts b/apps/web/src/fetchers/custom-field/delete-custom-field.ts
index f8d23c06e..8358041ef 100644
--- a/apps/web/src/fetchers/custom-field/delete-custom-field.ts
+++ b/apps/web/src/fetchers/custom-field/delete-custom-field.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteCustomField({ id }: { id: string }) {
const response = await client["custom-field"][":id"].$delete({
param: { id },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/get-custom-field-filter-values.ts b/apps/web/src/fetchers/custom-field/get-custom-field-filter-values.ts
index 9089169c2..087adb05b 100644
--- a/apps/web/src/fetchers/custom-field/get-custom-field-filter-values.ts
+++ b/apps/web/src/fetchers/custom-field/get-custom-field-filter-values.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getCustomFieldFilterValues({
projectId,
}: {
@@ -12,8 +14,7 @@ async function getCustomFieldFilterValues({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/get-custom-field-values-by-project.ts b/apps/web/src/fetchers/custom-field/get-custom-field-values-by-project.ts
index 69a2516ea..38241afb4 100644
--- a/apps/web/src/fetchers/custom-field/get-custom-field-values-by-project.ts
+++ b/apps/web/src/fetchers/custom-field/get-custom-field-values-by-project.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getCustomFieldValuesByProject({
projectId,
}: {
@@ -12,8 +14,7 @@ async function getCustomFieldValuesByProject({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/get-custom-field-values-by-task.ts b/apps/web/src/fetchers/custom-field/get-custom-field-values-by-task.ts
index cb504a654..e3a0949ef 100644
--- a/apps/web/src/fetchers/custom-field/get-custom-field-values-by-task.ts
+++ b/apps/web/src/fetchers/custom-field/get-custom-field-values-by-task.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getCustomFieldValuesByTask({ taskId }: { taskId: string }) {
const response = await client["custom-field"].task[":taskId"].$get({
param: { taskId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/get-custom-fields-by-project.ts b/apps/web/src/fetchers/custom-field/get-custom-fields-by-project.ts
index 36d7e7517..86cc19f81 100644
--- a/apps/web/src/fetchers/custom-field/get-custom-fields-by-project.ts
+++ b/apps/web/src/fetchers/custom-field/get-custom-fields-by-project.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getCustomFieldsByProject({ projectId }: { projectId: string }) {
const response = await client["custom-field"].project[":projectId"].$get({
param: { projectId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/reorder-custom-field.ts b/apps/web/src/fetchers/custom-field/reorder-custom-field.ts
index cd6b632f8..3fe6f1cde 100644
--- a/apps/web/src/fetchers/custom-field/reorder-custom-field.ts
+++ b/apps/web/src/fetchers/custom-field/reorder-custom-field.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function reorderCustomFields(
projectId: string,
fields: Array<{ id: string; position: number }>,
@@ -10,8 +12,7 @@ async function reorderCustomFields(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/custom-field/set-custom-field-value.ts b/apps/web/src/fetchers/custom-field/set-custom-field-value.ts
index 4b537953c..a0162d4f6 100644
--- a/apps/web/src/fetchers/custom-field/set-custom-field-value.ts
+++ b/apps/web/src/fetchers/custom-field/set-custom-field-value.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type SetCustomFieldValueRequest = InferRequestType<
(typeof client)["custom-field"]["value"]["$put"]
@@ -15,8 +16,7 @@ async function setCustomFieldValue({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/discord-integration/create-discord-integration.ts b/apps/web/src/fetchers/discord-integration/create-discord-integration.ts
index e9cda79fc..1746976a0 100644
--- a/apps/web/src/fetchers/discord-integration/create-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/create-discord-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { DiscordIntegration } from "./get-discord-integration";
export type CreateDiscordIntegrationRequest = {
@@ -31,8 +32,7 @@ async function createDiscordIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as DiscordIntegration;
diff --git a/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts b/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts
index 256273e06..e124b4826 100644
--- a/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/delete-discord-integration.ts
@@ -1,5 +1,7 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
+
async function deleteDiscordIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/discord-integration/project/${projectId}`),
@@ -13,8 +15,7 @@ async function deleteDiscordIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/discord-integration/get-discord-integration.ts b/apps/web/src/fetchers/discord-integration/get-discord-integration.ts
index 78c30b2dd..23c3b0c85 100644
--- a/apps/web/src/fetchers/discord-integration/get-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/get-discord-integration.ts
@@ -1,5 +1,6 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
export type DiscordIntegration = {
id: string;
projectId: string;
@@ -28,8 +29,7 @@ async function getDiscordIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as DiscordIntegration;
diff --git a/apps/web/src/fetchers/discord-integration/update-discord-integration.ts b/apps/web/src/fetchers/discord-integration/update-discord-integration.ts
index f92b1d2c8..7439301f8 100644
--- a/apps/web/src/fetchers/discord-integration/update-discord-integration.ts
+++ b/apps/web/src/fetchers/discord-integration/update-discord-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { DiscordIntegration } from "./get-discord-integration";
export type UpdateDiscordIntegrationRequest = {
@@ -32,8 +33,7 @@ async function updateDiscordIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as DiscordIntegration;
diff --git a/apps/web/src/fetchers/external-link/get-external-links.ts b/apps/web/src/fetchers/external-link/get-external-links.ts
index 4fdfe0af5..f332311c0 100644
--- a/apps/web/src/fetchers/external-link/get-external-links.ts
+++ b/apps/web/src/fetchers/external-link/get-external-links.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getExternalLinks(taskId: string) {
const response = await client["external-link"].task[":taskId"].$get({
param: { taskId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts
index 0105ff066..cfccd173f 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/create-generic-webhook-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { GenericWebhookIntegration } from "./get-generic-webhook-integration";
export type CreateGenericWebhookIntegrationRequest = {
@@ -38,8 +39,7 @@ async function createGenericWebhookIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as GenericWebhookIntegration;
diff --git a/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts
index 2d284b11a..f55290a23 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/delete-generic-webhook-integration.ts
@@ -1,5 +1,7 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
+
async function deleteGenericWebhookIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/generic-webhook-integration/project/${projectId}`),
@@ -13,8 +15,7 @@ async function deleteGenericWebhookIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
index c79262f24..7f3114e72 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/get-generic-webhook-integration.ts
@@ -1,5 +1,6 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
export type GenericWebhookIntegration = {
id: string;
projectId: string;
@@ -38,8 +39,7 @@ async function getGenericWebhookIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as GenericWebhookIntegration | null;
diff --git a/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts b/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts
index 0ea18aff6..bafb72238 100644
--- a/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts
+++ b/apps/web/src/fetchers/generic-webhook-integration/update-generic-webhook-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { GenericWebhookIntegration } from "./get-generic-webhook-integration";
export type UpdateGenericWebhookIntegrationRequest = {
@@ -39,8 +40,7 @@ async function updateGenericWebhookIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as GenericWebhookIntegration;
diff --git a/apps/web/src/fetchers/gitea-integration/create-gitea-integration.ts b/apps/web/src/fetchers/gitea-integration/create-gitea-integration.ts
index f396a2193..dcb1f1da8 100644
--- a/apps/web/src/fetchers/gitea-integration/create-gitea-integration.ts
+++ b/apps/web/src/fetchers/gitea-integration/create-gitea-integration.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type CreateGiteaIntegrationRequest = {
baseUrl: string;
accessToken?: string;
@@ -25,7 +26,8 @@ async function createGiteaIntegration(
.catch(async () => ({
message: (await response.text()) || "Request failed",
}));
- throw new Error(
+ throw new HttpError(
+ response.status,
typeof error === "object" && error && "message" in error
? String(error.message)
: "Request failed",
diff --git a/apps/web/src/fetchers/gitea-integration/delete-gitea-integration.ts b/apps/web/src/fetchers/gitea-integration/delete-gitea-integration.ts
index 1562cff5a..0074e21fd 100644
--- a/apps/web/src/fetchers/gitea-integration/delete-gitea-integration.ts
+++ b/apps/web/src/fetchers/gitea-integration/delete-gitea-integration.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteGiteaIntegration(projectId: string) {
const response = await client["gitea-integration"].project[
":projectId"
@@ -8,8 +10,7 @@ async function deleteGiteaIntegration(projectId: string) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/gitea-integration/get-gitea-integration.ts b/apps/web/src/fetchers/gitea-integration/get-gitea-integration.ts
index fbe5b5d0e..3c58f8d25 100644
--- a/apps/web/src/fetchers/gitea-integration/get-gitea-integration.ts
+++ b/apps/web/src/fetchers/gitea-integration/get-gitea-integration.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getGiteaIntegration(projectId: string) {
const response = await client["gitea-integration"].project[":projectId"].$get(
{
@@ -8,8 +10,7 @@ async function getGiteaIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/gitea-integration/import-gitea-issues.ts b/apps/web/src/fetchers/gitea-integration/import-gitea-issues.ts
index ab11ab157..2e127f558 100644
--- a/apps/web/src/fetchers/gitea-integration/import-gitea-issues.ts
+++ b/apps/web/src/fetchers/gitea-integration/import-gitea-issues.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function importGiteaIssues(projectId: string) {
const response = await client["gitea-integration"]["import-issues"].$post({
json: { projectId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/gitea-integration/list-gitea-repositories.ts b/apps/web/src/fetchers/gitea-integration/list-gitea-repositories.ts
index d7c6e740f..f298b564e 100644
--- a/apps/web/src/fetchers/gitea-integration/list-gitea-repositories.ts
+++ b/apps/web/src/fetchers/gitea-integration/list-gitea-repositories.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType, InferResponseType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type ListGiteaRepositoriesRequest = InferRequestType<
(typeof client)["gitea-integration"]["repositories"]["$post"]
@@ -18,8 +19,10 @@ async function listGiteaRepositories(
});
if (!response.ok) {
- const err = await response.text();
- throw new Error(err || "Request failed");
+ throw new HttpError(
+ response.status,
+ (await response.text()) || "Request failed",
+ );
}
return response.json();
diff --git a/apps/web/src/fetchers/gitea-integration/update-gitea-integration.ts b/apps/web/src/fetchers/gitea-integration/update-gitea-integration.ts
index 1b268f446..c8f8c4441 100644
--- a/apps/web/src/fetchers/gitea-integration/update-gitea-integration.ts
+++ b/apps/web/src/fetchers/gitea-integration/update-gitea-integration.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type UpdateGiteaIntegrationRequest = InferRequestType<
(typeof client)["gitea-integration"]["project"][":projectId"]["$patch"]
@@ -23,7 +24,8 @@ async function updateGiteaIntegration(
.catch(async () => ({
message: (await response.text()) || "Request failed",
}));
- throw new Error(
+ throw new HttpError(
+ response.status,
typeof error === "object" && error && "message" in error
? String(error.message)
: "Request failed",
diff --git a/apps/web/src/fetchers/gitea-integration/verify-gitea-access.ts b/apps/web/src/fetchers/gitea-integration/verify-gitea-access.ts
index 6cca8a355..ece5aa5f0 100644
--- a/apps/web/src/fetchers/gitea-integration/verify-gitea-access.ts
+++ b/apps/web/src/fetchers/gitea-integration/verify-gitea-access.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType, InferResponseType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type VerifyGiteaAccessRequest = InferRequestType<
(typeof client)["gitea-integration"]["verify"]["$post"]
@@ -21,7 +22,8 @@ async function verifyGiteaAccess(
const error = await response
.json()
.catch(() => ({ message: "Request failed" }));
- throw new Error(
+ throw new HttpError(
+ response.status,
typeof error === "object" && error && "message" in error
? String((error as { message: string }).message)
: "Request failed",
diff --git a/apps/web/src/fetchers/github-integration/create-github-integration.ts b/apps/web/src/fetchers/github-integration/create-github-integration.ts
index 67ff6ae90..a3e7086de 100644
--- a/apps/web/src/fetchers/github-integration/create-github-integration.ts
+++ b/apps/web/src/fetchers/github-integration/create-github-integration.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type CreateGithubIntegrationRequest = InferRequestType<
(typeof client)["github-integration"]["project"][":projectId"]["$post"]
@@ -17,8 +18,7 @@ async function createGithubIntegration(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/github-integration/delete-github-integration.ts b/apps/web/src/fetchers/github-integration/delete-github-integration.ts
index 68c5bee1d..ab98a13b1 100644
--- a/apps/web/src/fetchers/github-integration/delete-github-integration.ts
+++ b/apps/web/src/fetchers/github-integration/delete-github-integration.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteGithubIntegration(projectId: string) {
const response = await client["github-integration"].project[
":projectId"
@@ -8,8 +10,7 @@ async function deleteGithubIntegration(projectId: string) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/github-integration/get-app-info.ts b/apps/web/src/fetchers/github-integration/get-app-info.ts
index 4b7353c3d..655aed28a 100644
--- a/apps/web/src/fetchers/github-integration/get-app-info.ts
+++ b/apps/web/src/fetchers/github-integration/get-app-info.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferResponseType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type GitHubAppInfo = InferResponseType<
(typeof client)["github-integration"]["app-info"]["$get"],
@@ -10,8 +11,7 @@ export default async function getGitHubAppInfo(): Promise<GitHubAppInfo> {
const response = await client["github-integration"]["app-info"].$get();
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/github-integration/get-github-integration.ts b/apps/web/src/fetchers/github-integration/get-github-integration.ts
index 66973dcec..0ed62c648 100644
--- a/apps/web/src/fetchers/github-integration/get-github-integration.ts
+++ b/apps/web/src/fetchers/github-integration/get-github-integration.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getGithubIntegration(projectId: string) {
const response = await client["github-integration"].project[
":projectId"
@@ -8,8 +10,7 @@ async function getGithubIntegration(projectId: string) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/github-integration/import-github-issues.ts b/apps/web/src/fetchers/github-integration/import-github-issues.ts
index f2897bebf..6f24826d1 100644
--- a/apps/web/src/fetchers/github-integration/import-github-issues.ts
+++ b/apps/web/src/fetchers/github-integration/import-github-issues.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type ImportGithubIssuesRequest = InferRequestType<
(typeof client)["github-integration"]["import-issues"]["$post"]
@@ -11,8 +12,7 @@ async function importGithubIssues(data: ImportGithubIssuesRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/github-integration/list-repositories.ts b/apps/web/src/fetchers/github-integration/list-repositories.ts
index 468400240..7f207d1bc 100644
--- a/apps/web/src/fetchers/github-integration/list-repositories.ts
+++ b/apps/web/src/fetchers/github-integration/list-repositories.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferResponseType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type ListRepositoriesResponse = InferResponseType<
(typeof client)["github-integration"]["repositories"][":projectId"]["$get"],
@@ -16,8 +17,7 @@ async function listRepositories(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/github-integration/update-github-integration.ts b/apps/web/src/fetchers/github-integration/update-github-integration.ts
index e34c12965..85a551758 100644
--- a/apps/web/src/fetchers/github-integration/update-github-integration.ts
+++ b/apps/web/src/fetchers/github-integration/update-github-integration.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type UpdateGithubIntegrationRequest = InferRequestType<
(typeof client)["github-integration"]["project"][":projectId"]["$patch"]
@@ -17,8 +18,7 @@ async function updateGithubIntegration(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/github-integration/verify-github-installation.ts b/apps/web/src/fetchers/github-integration/verify-github-installation.ts
index 4cb8b888d..4a53c1e24 100644
--- a/apps/web/src/fetchers/github-integration/verify-github-installation.ts
+++ b/apps/web/src/fetchers/github-integration/verify-github-installation.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType, InferResponseType } from "hono";
+import { HttpError } from "@/lib/http-error";
export type VerifyGithubInstallationRequest = InferRequestType<
(typeof client)["github-integration"]["verify"]["$post"]
@@ -18,8 +19,10 @@ async function verifyGithubInstallation(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error || "Request failed");
+ throw new HttpError(
+ response.status,
+ (await response.text()) || "Request failed",
+ );
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/instance/get-instance-status.ts b/apps/web/src/fetchers/instance/get-instance-status.ts
index 569c70ce8..4cfd9c9f3 100644
--- a/apps/web/src/fetchers/instance/get-instance-status.ts
+++ b/apps/web/src/fetchers/instance/get-instance-status.ts
@@ -1,4 +1,5 @@
import { resolveApiBaseUrl } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type InstanceStatus = {
hasUsers: boolean;
@@ -17,10 +18,11 @@ export async function getInstanceStatus(): Promise<InstanceStatus> {
try {
detail = (await response.text()).trim();
} catch {}
- throw new Error(
+ throw new HttpError(
+ response.status,
detail
- ? `Failed to fetch instance status (${response.status}): ${detail}`
- : `Failed to fetch instance status (${response.status})`,
+ ? `Failed to fetch instance status: ${detail}`
+ : "Failed to fetch instance status",
);
}
return response.json();
diff --git a/apps/web/src/fetchers/invitation/get-invitation-details.ts b/apps/web/src/fetchers/invitation/get-invitation-details.ts
index 8c148eaa0..83c6ef7e6 100644
--- a/apps/web/src/fetchers/invitation/get-invitation-details.ts
+++ b/apps/web/src/fetchers/invitation/get-invitation-details.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type InvitationDetails = {
id: string;
email: string;
@@ -26,8 +27,7 @@ export async function getInvitationDetails(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const result = await response.json();
diff --git a/apps/web/src/fetchers/label/attach-label-to-task.ts b/apps/web/src/fetchers/label/attach-label-to-task.ts
index b96c08313..e4aaf6283 100644
--- a/apps/web/src/fetchers/label/attach-label-to-task.ts
+++ b/apps/web/src/fetchers/label/attach-label-to-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type AttachLabelToTaskRequest = {
labelId: string;
taskId: string;
@@ -15,7 +16,7 @@ async function attachLabelToTask({
});
if (!response.ok) {
- throw new Error(await response.text());
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/label/create-label.ts b/apps/web/src/fetchers/label/create-label.ts
index dea6c981e..1f5bfefae 100644
--- a/apps/web/src/fetchers/label/create-label.ts
+++ b/apps/web/src/fetchers/label/create-label.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateLabelRequest = InferRequestType<
(typeof client)["label"]["$post"]
@@ -21,8 +22,7 @@ async function createLabel({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/label/delete-label.ts b/apps/web/src/fetchers/label/delete-label.ts
index bc8ec8af1..b498a198c 100644
--- a/apps/web/src/fetchers/label/delete-label.ts
+++ b/apps/web/src/fetchers/label/delete-label.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type DeleteLabelRequest = InferRequestType<
(typeof client)["label"][":id"]["$delete"]
@@ -11,8 +12,7 @@ async function deleteLabel({ id }: DeleteLabelRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/label/detach-label-from-task.ts b/apps/web/src/fetchers/label/detach-label-from-task.ts
index d5d46ccb2..7d0e453ab 100644
--- a/apps/web/src/fetchers/label/detach-label-from-task.ts
+++ b/apps/web/src/fetchers/label/detach-label-from-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type DetachLabelFromTaskRequest = {
labelId: string;
};
@@ -10,7 +11,7 @@ async function detachLabelFromTask({ labelId }: DetachLabelFromTaskRequest) {
});
if (!response.ok) {
- throw new Error(await response.text());
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/label/get-label-by-workspace.ts b/apps/web/src/fetchers/label/get-label-by-workspace.ts
index 0c27b17f0..61d57d7b1 100644
--- a/apps/web/src/fetchers/label/get-label-by-workspace.ts
+++ b/apps/web/src/fetchers/label/get-label-by-workspace.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetLabelsByTaskRequest = InferRequestType<
(typeof client)["label"]["workspace"][":workspaceId"]["$get"]
@@ -13,8 +14,7 @@ async function getLabelsByTask({ workspaceId }: GetLabelsByTaskRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/label/get-labels-by-task.ts b/apps/web/src/fetchers/label/get-labels-by-task.ts
index 986f6db1a..302f64cf1 100644
--- a/apps/web/src/fetchers/label/get-labels-by-task.ts
+++ b/apps/web/src/fetchers/label/get-labels-by-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetLabelsByTaskRequest = InferRequestType<
(typeof client)["label"]["task"][":taskId"]["$get"]
@@ -13,8 +14,7 @@ async function getLabelsByTask({ taskId }: GetLabelsByTaskRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/label/update-label.ts b/apps/web/src/fetchers/label/update-label.ts
index e7dbd2c7b..7c8f6120e 100644
--- a/apps/web/src/fetchers/label/update-label.ts
+++ b/apps/web/src/fetchers/label/update-label.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type UpdateLabelRequest = InferRequestType<
(typeof client)["label"][":id"]["$put"]
@@ -13,8 +14,7 @@ async function updateLabel({ id, name, color }: UpdateLabelRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/mattermost-integration/create-mattermost-integration.ts b/apps/web/src/fetchers/mattermost-integration/create-mattermost-integration.ts
index 3c3e78ee0..94c6a81db 100644
--- a/apps/web/src/fetchers/mattermost-integration/create-mattermost-integration.ts
+++ b/apps/web/src/fetchers/mattermost-integration/create-mattermost-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { MattermostIntegration } from "./get-mattermost-integration";
export type CreateMattermostIntegrationRequest = {
@@ -31,8 +32,7 @@ async function createMattermostIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as MattermostIntegration;
diff --git a/apps/web/src/fetchers/mattermost-integration/delete-mattermost-integration.ts b/apps/web/src/fetchers/mattermost-integration/delete-mattermost-integration.ts
index 5b97773c9..5cbad6fd0 100644
--- a/apps/web/src/fetchers/mattermost-integration/delete-mattermost-integration.ts
+++ b/apps/web/src/fetchers/mattermost-integration/delete-mattermost-integration.ts
@@ -1,5 +1,7 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
+
async function deleteMattermostIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/mattermost-integration/project/${projectId}`),
@@ -13,8 +15,7 @@ async function deleteMattermostIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/mattermost-integration/get-mattermost-integration.ts b/apps/web/src/fetchers/mattermost-integration/get-mattermost-integration.ts
index 460ab931d..e3de1150b 100644
--- a/apps/web/src/fetchers/mattermost-integration/get-mattermost-integration.ts
+++ b/apps/web/src/fetchers/mattermost-integration/get-mattermost-integration.ts
@@ -1,5 +1,6 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
export type MattermostIntegration = {
id: string;
projectId: string;
@@ -28,8 +29,7 @@ async function getMattermostIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as MattermostIntegration;
diff --git a/apps/web/src/fetchers/mattermost-integration/update-mattermost-integration.ts b/apps/web/src/fetchers/mattermost-integration/update-mattermost-integration.ts
index c43fb9c00..747177b7b 100644
--- a/apps/web/src/fetchers/mattermost-integration/update-mattermost-integration.ts
+++ b/apps/web/src/fetchers/mattermost-integration/update-mattermost-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { MattermostIntegration } from "./get-mattermost-integration";
export type UpdateMattermostIntegrationRequest = {
@@ -32,8 +33,7 @@ async function updateMattermostIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as MattermostIntegration;
diff --git a/apps/web/src/fetchers/notification-preferences/delete-notification-workspace-rule.ts b/apps/web/src/fetchers/notification-preferences/delete-notification-workspace-rule.ts
index b3f3defba..2e1998612 100644
--- a/apps/web/src/fetchers/notification-preferences/delete-notification-workspace-rule.ts
+++ b/apps/web/src/fetchers/notification-preferences/delete-notification-workspace-rule.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { NotificationPreferences } from "./get-notification-preferences";
async function deleteNotificationWorkspaceRule(
@@ -13,8 +14,7 @@ async function deleteNotificationWorkspaceRule(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as NotificationPreferences;
diff --git a/apps/web/src/fetchers/notification-preferences/get-notification-preferences.ts b/apps/web/src/fetchers/notification-preferences/get-notification-preferences.ts
index b0dbe6f40..00a3ce175 100644
--- a/apps/web/src/fetchers/notification-preferences/get-notification-preferences.ts
+++ b/apps/web/src/fetchers/notification-preferences/get-notification-preferences.ts
@@ -1,5 +1,6 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
export type NotificationPreferenceWorkspaceRule = {
id: string;
workspaceId: string;
@@ -50,8 +51,7 @@ async function getNotificationPreferences(): Promise<NotificationPreferences> {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as NotificationPreferences;
diff --git a/apps/web/src/fetchers/notification-preferences/update-notification-preferences.ts b/apps/web/src/fetchers/notification-preferences/update-notification-preferences.ts
index dfd2279d2..a807f67f9 100644
--- a/apps/web/src/fetchers/notification-preferences/update-notification-preferences.ts
+++ b/apps/web/src/fetchers/notification-preferences/update-notification-preferences.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { NotificationPreferences } from "./get-notification-preferences";
export type UpdateNotificationPreferencesRequest = {
@@ -33,8 +34,7 @@ async function updateNotificationPreferences(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as NotificationPreferences;
diff --git a/apps/web/src/fetchers/notification-preferences/upsert-notification-workspace-rule.ts b/apps/web/src/fetchers/notification-preferences/upsert-notification-workspace-rule.ts
index de84ac388..ba9e6d9cc 100644
--- a/apps/web/src/fetchers/notification-preferences/upsert-notification-workspace-rule.ts
+++ b/apps/web/src/fetchers/notification-preferences/upsert-notification-workspace-rule.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { NotificationPreferences } from "./get-notification-preferences";
export type UpsertNotificationWorkspaceRuleRequest = {
@@ -28,8 +29,7 @@ async function upsertNotificationWorkspaceRule(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as NotificationPreferences;
diff --git a/apps/web/src/fetchers/notification/clear-notifications.ts b/apps/web/src/fetchers/notification/clear-notifications.ts
index 1b5ba29fa..a252bcccc 100644
--- a/apps/web/src/fetchers/notification/clear-notifications.ts
+++ b/apps/web/src/fetchers/notification/clear-notifications.ts
@@ -1,11 +1,12 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function clearNotifications() {
const response = await client.notification["clear-all"].$delete();
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/notification/get-notifications.ts b/apps/web/src/fetchers/notification/get-notifications.ts
index f0a0c953d..abe68365e 100644
--- a/apps/web/src/fetchers/notification/get-notifications.ts
+++ b/apps/web/src/fetchers/notification/get-notifications.ts
@@ -1,11 +1,12 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getNotifications() {
const response = await client.notification.$get();
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts b/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts
index 5f8126f35..d67d0db94 100644
--- a/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts
+++ b/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts
@@ -1,11 +1,12 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function markAllNotificationsAsRead() {
const response = await client.notification["read-all"].$patch();
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/notification/mark-notification-as-read.ts b/apps/web/src/fetchers/notification/mark-notification-as-read.ts
index 31a7b3270..4e63d1b97 100644
--- a/apps/web/src/fetchers/notification/mark-notification-as-read.ts
+++ b/apps/web/src/fetchers/notification/mark-notification-as-read.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function markNotificationAsRead(id: string) {
const response = await client.notification[":id"].read.$patch({
param: { id },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/oauth/get-id-token.ts b/apps/web/src/fetchers/oauth/get-id-token.ts
index 936d07de5..6a024f012 100644
--- a/apps/web/src/fetchers/oauth/get-id-token.ts
+++ b/apps/web/src/fetchers/oauth/get-id-token.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferResponseType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetIdTokenResponse = InferResponseType<
(typeof client)["oauth"]["id-token"]["$get"],
@@ -10,8 +11,7 @@ export async function getIdToken() {
const response = await client.oauth["id-token"].$get();
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/project/create-project.ts b/apps/web/src/fetchers/project/create-project.ts
index 83e9d0f00..1a2c558f2 100644
--- a/apps/web/src/fetchers/project/create-project.ts
+++ b/apps/web/src/fetchers/project/create-project.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateProjectRequest = InferRequestType<
(typeof client)["project"]["$post"]
@@ -16,8 +17,7 @@ async function createProject({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/project/delete-project.ts b/apps/web/src/fetchers/project/delete-project.ts
index 7bcd52197..a7dd4b1ca 100644
--- a/apps/web/src/fetchers/project/delete-project.ts
+++ b/apps/web/src/fetchers/project/delete-project.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type DeleteProjectRequest = InferRequestType<
(typeof client)["project"][":id"]["$delete"]
@@ -9,8 +10,7 @@ async function deleteProject({ id }: DeleteProjectRequest) {
const response = await client.project[":id"].$delete({ param: { id } });
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/project/get-project.ts b/apps/web/src/fetchers/project/get-project.ts
index 815276812..db0e14c7d 100644
--- a/apps/web/src/fetchers/project/get-project.ts
+++ b/apps/web/src/fetchers/project/get-project.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetProjectRequest = InferRequestType<
(typeof client)["project"][":id"]["$get"]
@@ -13,8 +14,7 @@ async function getProject({ id }: GetProjectRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/project/get-projects.ts b/apps/web/src/fetchers/project/get-projects.ts
index 6e8492bc5..cdca4b974 100644
--- a/apps/web/src/fetchers/project/get-projects.ts
+++ b/apps/web/src/fetchers/project/get-projects.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetProjectsRequest = InferRequestType<
(typeof client)["project"]["$get"]
@@ -11,8 +12,7 @@ async function getProjects({ workspaceId }: GetProjectsRequest) {
const response = await client.project.$get({ query: { workspaceId } });
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/project/get-public-project.ts b/apps/web/src/fetchers/project/get-public-project.ts
index 11ba7dd7b..f99e5282e 100644
--- a/apps/web/src/fetchers/project/get-public-project.ts
+++ b/apps/web/src/fetchers/project/get-public-project.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetPublicProjectRequest = InferRequestType<
(typeof client)["public-project"][":id"]["$get"]
@@ -11,8 +12,7 @@ async function getPublicProject({ id }: GetPublicProjectRequest) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/project/reorder-projects.ts b/apps/web/src/fetchers/project/reorder-projects.ts
index 3f5569e22..d3cc2111e 100644
--- a/apps/web/src/fetchers/project/reorder-projects.ts
+++ b/apps/web/src/fetchers/project/reorder-projects.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function reorderProjects(
workspaceId: string,
projects: Array<{ id: string; position: number }>,
@@ -10,8 +12,7 @@ async function reorderProjects(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/project/update-project.ts b/apps/web/src/fetchers/project/update-project.ts
index 0e57921d1..d92dabe55 100644
--- a/apps/web/src/fetchers/project/update-project.ts
+++ b/apps/web/src/fetchers/project/update-project.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type UpdateProjectRequest = InferRequestType<
(typeof client)["project"][":id"]["$put"]
@@ -20,8 +21,7 @@ async function updateProject({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/search/global-search.ts b/apps/web/src/fetchers/search/global-search.ts
index 831d2c4ed..9bbb5c4c3 100644
--- a/apps/web/src/fetchers/search/global-search.ts
+++ b/apps/web/src/fetchers/search/global-search.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
type SearchParams = {
q: string;
type?:
@@ -25,8 +27,7 @@ async function globalSearch(params: SearchParams) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/slack-integration/create-slack-integration.ts b/apps/web/src/fetchers/slack-integration/create-slack-integration.ts
index be06daf8d..f174d157a 100644
--- a/apps/web/src/fetchers/slack-integration/create-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/create-slack-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { SlackIntegration } from "./get-slack-integration";
export type CreateSlackIntegrationRequest = {
@@ -31,8 +32,7 @@ async function createSlackIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as SlackIntegration;
diff --git a/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts b/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts
index 18f8c72e6..04dbcf9a1 100644
--- a/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/delete-slack-integration.ts
@@ -1,5 +1,7 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
+
async function deleteSlackIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/slack-integration/project/${projectId}`),
@@ -13,8 +15,7 @@ async function deleteSlackIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/slack-integration/get-slack-integration.ts b/apps/web/src/fetchers/slack-integration/get-slack-integration.ts
index 1db89d15c..bdd819f21 100644
--- a/apps/web/src/fetchers/slack-integration/get-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/get-slack-integration.ts
@@ -1,5 +1,6 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
export type SlackIntegration = {
id: string;
projectId: string;
@@ -28,8 +29,7 @@ async function getSlackIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as SlackIntegration;
diff --git a/apps/web/src/fetchers/slack-integration/update-slack-integration.ts b/apps/web/src/fetchers/slack-integration/update-slack-integration.ts
index c6c5e81b2..3cbc65f58 100644
--- a/apps/web/src/fetchers/slack-integration/update-slack-integration.ts
+++ b/apps/web/src/fetchers/slack-integration/update-slack-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { SlackIntegration } from "./get-slack-integration";
export type UpdateSlackIntegrationRequest = {
@@ -32,8 +33,7 @@ async function updateSlackIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as SlackIntegration;
diff --git a/apps/web/src/fetchers/task-relation/create-task-relation.ts b/apps/web/src/fetchers/task-relation/create-task-relation.ts
index 4457bb47e..0b5d6ba90 100644
--- a/apps/web/src/fetchers/task-relation/create-task-relation.ts
+++ b/apps/web/src/fetchers/task-relation/create-task-relation.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function createTaskRelation({
sourceTaskId,
targetTaskId,
@@ -18,8 +20,7 @@ async function createTaskRelation({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task-relation/delete-task-relation.ts b/apps/web/src/fetchers/task-relation/delete-task-relation.ts
index ee3a9b621..b510ba702 100644
--- a/apps/web/src/fetchers/task-relation/delete-task-relation.ts
+++ b/apps/web/src/fetchers/task-relation/delete-task-relation.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteTaskRelation(id: string) {
const response = await client["task-relation"][":id"].$delete({
param: { id },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task-relation/get-task-relations.ts b/apps/web/src/fetchers/task-relation/get-task-relations.ts
index 8fac27bef..2dfbfb728 100644
--- a/apps/web/src/fetchers/task-relation/get-task-relations.ts
+++ b/apps/web/src/fetchers/task-relation/get-task-relations.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getTaskRelations(taskId: string) {
const response = await client["task-relation"][":taskId"].$get({
param: { taskId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/bulk-operation.ts b/apps/web/src/fetchers/task/bulk-operation.ts
index 8fad79753..261c5ae08 100644
--- a/apps/web/src/fetchers/task/bulk-operation.ts
+++ b/apps/web/src/fetchers/task/bulk-operation.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
type BulkOperationType =
| "updateStatus"
| "updatePriority"
@@ -23,8 +25,7 @@ async function bulkOperation({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/task/create-image-upload.ts b/apps/web/src/fetchers/task/create-image-upload.ts
index dff7d5825..babd643ca 100644
--- a/apps/web/src/fetchers/task/create-image-upload.ts
+++ b/apps/web/src/fetchers/task/create-image-upload.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function createImageUpload({
taskId,
filename,
@@ -24,8 +26,7 @@ async function createImageUpload({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
@@ -58,8 +59,7 @@ export async function finalizeImageUpload({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/task/create-task.ts b/apps/web/src/fetchers/task/create-task.ts
index 1919ee3fc..0039acc69 100644
--- a/apps/web/src/fetchers/task/create-task.ts
+++ b/apps/web/src/fetchers/task/create-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateTaskRequest = InferRequestType<
(typeof client)["task"][":projectId"]["$post"]
@@ -36,8 +37,7 @@ async function createTask(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/delete-task.ts b/apps/web/src/fetchers/task/delete-task.ts
index 70755fdea..90f048c90 100644
--- a/apps/web/src/fetchers/task/delete-task.ts
+++ b/apps/web/src/fetchers/task/delete-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type DeleteTaskRequest = InferRequestType<
(typeof client)["task"][":id"]["$delete"]
@@ -9,8 +10,7 @@ async function deleteTask(taskId: string) {
const response = await client.task[":id"].$delete({ param: { id: taskId } });
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/export-tasks.ts b/apps/web/src/fetchers/task/export-tasks.ts
index 93777ed2d..0e0632897 100644
--- a/apps/web/src/fetchers/task/export-tasks.ts
+++ b/apps/web/src/fetchers/task/export-tasks.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function exportTasks(projectId: string) {
const response = await client.task.export[":projectId"].$get({
param: { projectId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/get-task.ts b/apps/web/src/fetchers/task/get-task.ts
index 59f253625..13c42d35e 100644
--- a/apps/web/src/fetchers/task/get-task.ts
+++ b/apps/web/src/fetchers/task/get-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type GetTaskRequest = InferRequestType<
(typeof client)["task"][":id"]["$get"]
@@ -9,8 +10,7 @@ async function getTask(taskId: string) {
const response = await client.task[":id"].$get({ param: { id: taskId } });
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/import-tasks.ts b/apps/web/src/fetchers/task/import-tasks.ts
index 4952c984e..519836648 100644
--- a/apps/web/src/fetchers/task/import-tasks.ts
+++ b/apps/web/src/fetchers/task/import-tasks.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
export type TaskToImport = {
title: string;
description?: string;
@@ -17,8 +18,7 @@ async function importTasks(projectId: string, tasks: TaskToImport[]) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/move-task.ts b/apps/web/src/fetchers/task/move-task.ts
index 3f9d58a5b..6aa846fee 100644
--- a/apps/web/src/fetchers/task/move-task.ts
+++ b/apps/web/src/fetchers/task/move-task.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function moveTask({
taskId,
destinationProjectId,
@@ -30,7 +32,7 @@ async function moveTask({
(await response.text().catch(() => "")) ||
`API error ${response.status}`;
}
- throw new Error(message);
+ throw new HttpError(response.status, message);
}
return response.json();
diff --git a/apps/web/src/fetchers/task/update-task-assignee.ts b/apps/web/src/fetchers/task/update-task-assignee.ts
index 41e76b633..874296067 100644
--- a/apps/web/src/fetchers/task/update-task-assignee.ts
+++ b/apps/web/src/fetchers/task/update-task-assignee.ts
@@ -1,4 +1,5 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
type UpdateTaskAssigneePayload = Pick<Task, "userId">;
@@ -15,8 +16,7 @@ async function updateTaskAssignee(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/update-task-description.ts b/apps/web/src/fetchers/task/update-task-description.ts
index af23e2397..9dd0f5d32 100644
--- a/apps/web/src/fetchers/task/update-task-description.ts
+++ b/apps/web/src/fetchers/task/update-task-description.ts
@@ -1,4 +1,5 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
async function updateTaskDescription(taskId: string, task: Task) {
@@ -10,8 +11,7 @@ async function updateTaskDescription(taskId: string, task: Task) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/update-task-due-date.ts b/apps/web/src/fetchers/task/update-task-due-date.ts
index 335c4185f..4d2b35cc0 100644
--- a/apps/web/src/fetchers/task/update-task-due-date.ts
+++ b/apps/web/src/fetchers/task/update-task-due-date.ts
@@ -1,4 +1,5 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
async function updateTaskDueDate(taskId: string, task: Task) {
@@ -10,8 +11,7 @@ async function updateTaskDueDate(taskId: string, task: Task) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/update-task-priority.ts b/apps/web/src/fetchers/task/update-task-priority.ts
index f54285955..13197126b 100644
--- a/apps/web/src/fetchers/task/update-task-priority.ts
+++ b/apps/web/src/fetchers/task/update-task-priority.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
type UpdateTaskPriorityValue = InferRequestType<
@@ -15,8 +16,7 @@ async function updateTaskPriority(taskId: string, task: Task) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/update-task-status.ts b/apps/web/src/fetchers/task/update-task-status.ts
index 13e60e42a..00fbbf634 100644
--- a/apps/web/src/fetchers/task/update-task-status.ts
+++ b/apps/web/src/fetchers/task/update-task-status.ts
@@ -1,4 +1,5 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
type UpdateTaskStatusPayload = Pick<Task, "status">;
@@ -12,8 +13,7 @@ async function updateTaskStatus(taskId: string, task: UpdateTaskStatusPayload) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/update-task-title.ts b/apps/web/src/fetchers/task/update-task-title.ts
index 81ce7c226..8bd5d3712 100644
--- a/apps/web/src/fetchers/task/update-task-title.ts
+++ b/apps/web/src/fetchers/task/update-task-title.ts
@@ -1,4 +1,5 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
async function updateTaskTitle(taskId: string, task: Task) {
@@ -10,8 +11,7 @@ async function updateTaskTitle(taskId: string, task: Task) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/task/update-task.ts b/apps/web/src/fetchers/task/update-task.ts
index 7eed2b1d8..c0b1a7bce 100644
--- a/apps/web/src/fetchers/task/update-task.ts
+++ b/apps/web/src/fetchers/task/update-task.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
import type Task from "@/types/task";
type UpdateTaskPriority = InferRequestType<
@@ -27,8 +28,7 @@ async function updateTask(taskId: string, task: Task) {
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/telegram-integration/create-telegram-integration.ts b/apps/web/src/fetchers/telegram-integration/create-telegram-integration.ts
index 41099812b..5361e20c5 100644
--- a/apps/web/src/fetchers/telegram-integration/create-telegram-integration.ts
+++ b/apps/web/src/fetchers/telegram-integration/create-telegram-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { TelegramIntegration } from "./get-telegram-integration";
export type CreateTelegramIntegrationRequest = {
@@ -33,8 +34,7 @@ async function createTelegramIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as TelegramIntegration;
diff --git a/apps/web/src/fetchers/telegram-integration/delete-telegram-integration.ts b/apps/web/src/fetchers/telegram-integration/delete-telegram-integration.ts
index eb3a950fd..db787cf31 100644
--- a/apps/web/src/fetchers/telegram-integration/delete-telegram-integration.ts
+++ b/apps/web/src/fetchers/telegram-integration/delete-telegram-integration.ts
@@ -1,5 +1,7 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
+
async function deleteTelegramIntegration(projectId: string) {
const response = await fetch(
getApiUrl(`/telegram-integration/project/${projectId}`),
@@ -10,8 +12,7 @@ async function deleteTelegramIntegration(projectId: string) {
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as { success: boolean };
diff --git a/apps/web/src/fetchers/telegram-integration/get-telegram-integration.ts b/apps/web/src/fetchers/telegram-integration/get-telegram-integration.ts
index 8a30acf58..cdc361376 100644
--- a/apps/web/src/fetchers/telegram-integration/get-telegram-integration.ts
+++ b/apps/web/src/fetchers/telegram-integration/get-telegram-integration.ts
@@ -1,5 +1,6 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
export type TelegramIntegration = {
id: string;
projectId: string;
@@ -34,8 +35,7 @@ async function getTelegramIntegration(projectId: string) {
}
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as TelegramIntegration;
diff --git a/apps/web/src/fetchers/telegram-integration/update-telegram-integration.ts b/apps/web/src/fetchers/telegram-integration/update-telegram-integration.ts
index 2a50682f9..d8b0f5119 100644
--- a/apps/web/src/fetchers/telegram-integration/update-telegram-integration.ts
+++ b/apps/web/src/fetchers/telegram-integration/update-telegram-integration.ts
@@ -1,4 +1,5 @@
import { getApiUrl } from "@/fetchers/get-api-url";
+import { HttpError } from "@/lib/http-error";
import type { TelegramIntegration } from "./get-telegram-integration";
export type UpdateTelegramIntegrationRequest = {
@@ -34,8 +35,7 @@ async function updateTelegramIntegration(
);
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return (await response.json()) as TelegramIntegration;
diff --git a/apps/web/src/fetchers/time-entry/create-time-entry.ts b/apps/web/src/fetchers/time-entry/create-time-entry.ts
index 03fe2fc70..91e198aa9 100644
--- a/apps/web/src/fetchers/time-entry/create-time-entry.ts
+++ b/apps/web/src/fetchers/time-entry/create-time-entry.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type CreateTimeEntryRequest = InferRequestType<
(typeof client)["time-entry"]["$post"]
@@ -19,8 +20,7 @@ async function createTimeEntry({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/time-entry/get-time-entries.ts b/apps/web/src/fetchers/time-entry/get-time-entries.ts
index 62e40819a..22bff9901 100644
--- a/apps/web/src/fetchers/time-entry/get-time-entries.ts
+++ b/apps/web/src/fetchers/time-entry/get-time-entries.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getTimeEntriesByTaskId(taskId: string) {
const response = await client["time-entry"].task[":taskId"].$get({
param: { taskId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/time-entry/update-time-entry.ts b/apps/web/src/fetchers/time-entry/update-time-entry.ts
index 935c3dd89..f1b784778 100644
--- a/apps/web/src/fetchers/time-entry/update-time-entry.ts
+++ b/apps/web/src/fetchers/time-entry/update-time-entry.ts
@@ -1,5 +1,6 @@
import { client } from "@kaneo/libs";
import type { InferRequestType } from "hono/client";
+import { HttpError } from "@/lib/http-error";
export type UpdateTimeEntryRequest = InferRequestType<
(typeof client)["time-entry"][":id"]["$put"]
@@ -23,8 +24,7 @@ async function updateTimeEntry({
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
const data = await response.json();
diff --git a/apps/web/src/fetchers/user/delete-avatar.ts b/apps/web/src/fetchers/user/delete-avatar.ts
index 04e849832..b55099751 100644
--- a/apps/web/src/fetchers/user/delete-avatar.ts
+++ b/apps/web/src/fetchers/user/delete-avatar.ts
@@ -1,10 +1,12 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteAvatar() {
const response = await client.user.avatar.$delete();
if (!response.ok) {
- throw new Error(await response.text());
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/user/upload-avatar.ts b/apps/web/src/fetchers/user/upload-avatar.ts
index 46f925b15..25e5152b3 100644
--- a/apps/web/src/fetchers/user/upload-avatar.ts
+++ b/apps/web/src/fetchers/user/upload-avatar.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function uploadAvatar({
contentType,
data,
@@ -12,7 +14,7 @@ async function uploadAvatar({
});
if (!response.ok) {
- throw new Error(await response.text());
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/workflow-rule/delete-workflow-rule.ts b/apps/web/src/fetchers/workflow-rule/delete-workflow-rule.ts
index 08301c414..a67267ab1 100644
--- a/apps/web/src/fetchers/workflow-rule/delete-workflow-rule.ts
+++ b/apps/web/src/fetchers/workflow-rule/delete-workflow-rule.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function deleteWorkflowRule(id: string) {
const response = await client["workflow-rule"][":id"].$delete({
param: { id },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/workflow-rule/get-workflow-rules.ts b/apps/web/src/fetchers/workflow-rule/get-workflow-rules.ts
index 87bbfd07f..fcbb1d582 100644
--- a/apps/web/src/fetchers/workflow-rule/get-workflow-rules.ts
+++ b/apps/web/src/fetchers/workflow-rule/get-workflow-rules.ts
@@ -1,13 +1,14 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function getWorkflowRules(projectId: string) {
const response = await client["workflow-rule"][":projectId"].$get({
param: { projectId },
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();
diff --git a/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts b/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts
index c17560a82..d83d21578 100644
--- a/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts
+++ b/apps/web/src/fetchers/workflow-rule/upsert-workflow-rule.ts
@@ -1,5 +1,7 @@
import { client } from "@kaneo/libs";
+import { HttpError } from "@/lib/http-error";
+
async function upsertWorkflowRule(
projectId: string,
data: { integrationType: string; eventType: string; columnId: string },
@@ -10,8 +12,7 @@ async function upsertWorkflowRule(
});
if (!response.ok) {
- const error = await response.text();
- throw new Error(error);
+ throw new HttpError(response.status, await response.text());
}
return response.json();