This repository has been archived on 2026-07-27. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
aniwatch-api/src/config/errorHandler.ts
T
2025-05-11 13:31:58 +05:30

29 lines
825 B
TypeScript

import { HiAnimeError } from "aniwatch";
import type { ErrorHandler, NotFoundHandler } from "hono";
import type { ContentfulStatusCode } from "hono/utils/http-status";
import { log } from "./logger.js";
const errResp: { status: ContentfulStatusCode; message: string } = {
status: 500,
message: "Internal Server Error",
};
export const errorHandler: ErrorHandler = (err, c) => {
log.error(JSON.stringify(err));
if (err instanceof HiAnimeError) {
errResp.status = err.status as ContentfulStatusCode;
errResp.message = err.message;
}
return c.json(errResp, errResp.status);
};
export const notFoundHandler: NotFoundHandler = (c) => {
errResp.status = 404;
errResp.message = "Not Found";
log.error(JSON.stringify(errResp));
return c.json(errResp, errResp.status);
};