diff options
| -rw-r--r-- | src/config/errorHandler.ts | 26 |
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 }); +}; |
