aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRitesh Ghosh <[email protected]>2024-12-24 17:09:43 +0530
committerRitesh Ghosh <[email protected]>2024-12-24 17:09:43 +0530
commitda19fb7e869c7a9f4007b8bf1439c08e5fe684f7 (patch)
treef1336f9cd85ac2c0ca8dafc025cf26c2bf369106
parent7e9f9207849296cb19be11c37e1a5dfbf75fdead (diff)
downloadaniwatch-api-da19fb7e869c7a9f4007b8bf1439c08e5fe684f7.tar.xz
aniwatch-api-da19fb7e869c7a9f4007b8bf1439c08e5fe684f7.zip
feat(errorHandling): add error handlers config file
-rw-r--r--src/config/errorHandler.ts26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/config/errorHandler.ts b/src/config/errorHandler.ts
new file mode 100644
index 0000000..4333687
--- /dev/null
+++ b/src/config/errorHandler.ts
@@ -0,0 +1,26 @@
+import { HiAnimeError } from "aniwatch";
+import type { ErrorHandler, NotFoundHandler } from "hono";
+
+const errResp: { status: number; message: string } = {
+ status: 500,
+ message: "Internal Server Error",
+};
+
+export const errorHandler: ErrorHandler = (err, c) => {
+ console.error(err);
+
+ if (err instanceof HiAnimeError) {
+ errResp.status = err.status;
+ errResp.message = err.message;
+ }
+
+ return c.json(errResp, { status: errResp.status });
+};
+
+export const notFoundHandler: NotFoundHandler = (c) => {
+ errResp.status = 404;
+ errResp.message = "Not Found";
+
+ console.error(errResp);
+ return c.json(errResp, { status: errResp.status });
+};