feat: integrate use of ebvalidated envs

This commit is contained in:
Ritesh Ghosh
2025-05-11 13:07:04 +05:30
parent fc92194407
commit 5e028771f0
4 changed files with 64 additions and 57 deletions
+13 -12
View File
@@ -1,27 +1,28 @@
import { HiAnimeError } from "aniwatch";
import type { ErrorHandler, NotFoundHandler } from "hono";
import type { ContentfulStatusCode } from "hono/utils/http-status";
import { logger } from "./logger.js";
const errResp: { status: ContentfulStatusCode; message: string } = {
status: 500,
message: "Internal Server Error",
status: 500,
message: "Internal Server Error",
};
export const errorHandler: ErrorHandler = (err, c) => {
console.error(err);
logger.error(JSON.stringify(err));
if (err instanceof HiAnimeError) {
errResp.status = err.status as ContentfulStatusCode;
errResp.message = err.message;
}
if (err instanceof HiAnimeError) {
errResp.status = err.status as ContentfulStatusCode;
errResp.message = err.message;
}
return c.json(errResp, errResp.status);
return c.json(errResp, errResp.status);
};
export const notFoundHandler: NotFoundHandler = (c) => {
errResp.status = 404;
errResp.message = "Not Found";
errResp.status = 404;
errResp.message = "Not Found";
console.error(errResp);
return c.json(errResp, errResp.status);
logger.error(JSON.stringify(errResp));
return c.json(errResp, errResp.status);
};