feat: integrate use of ebvalidated envs
This commit is contained in:
+13
-12
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user