blob: d6f31932d1458d4a717e5778c6b00945206d476d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { HiAnimeError } from "aniwatch";
import type { ErrorHandler, NotFoundHandler } from "hono";
import type { ContentfulStatusCode } from "hono/utils/http-status";
const errResp: { status: ContentfulStatusCode; 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 as ContentfulStatusCode;
errResp.message = err.message;
}
return c.json(errResp, errResp.status);
};
export const notFoundHandler: NotFoundHandler = (c) => {
errResp.status = 404;
errResp.message = "Not Found";
console.error(errResp);
return c.json(errResp, errResp.status);
};
|