Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { Status } from "@hey/data/enums";
2import { ERRORS } from "@hey/data/errors";
3import { withPrefix } from "@hey/helpers/logger";
4import type { Context } from "hono";
5import ApiError from "@/utils/apiError";
6
7const handleApiError = (ctx: Context, error?: unknown): Response => {
8 const log = withPrefix("[API]");
9 log.error(error);
10
11 if (error instanceof ApiError) {
12 ctx.status(error.statusCode);
13 return ctx.json({ error: error.message, status: Status.Error });
14 }
15
16 ctx.status(500);
17 return ctx.json({ error: ERRORS.SomethingWentWrong, status: Status.Error });
18};
19
20export default handleApiError;