Skip to content

Commit

Permalink
Add generic error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Nov 5, 2024
1 parent 6bf4be3 commit 26825c0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FUEL_TYPE } from "./types";
import v1 from "./v1";
import { Ratelimit } from "@upstash/ratelimit";
import redis from "./config/redis";
import { HTTPException } from "hono/http-exception";

const ratelimit = new Ratelimit({
redis,
Expand Down Expand Up @@ -46,6 +47,12 @@ if (process.env.FEATURE_FLAG_RATE_LIMIT) {
// return next();
// });

app.onError((err, c) => {
if (err instanceof HTTPException) {
return c.json({ status: err.status, message: err.message }, 500);
}
});

app.notFound((c) =>
c.json({ message: `Resource not found: ${c.req.path}` }, 404),
);
Expand Down

0 comments on commit 26825c0

Please sign in to comment.