Skip to content

Commit bbeda87

Browse files
committed
Merge branch 'fix/payload'
2 parents ab28525 + e838b45 commit bbeda87

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/server.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Hono } from "hono"
22
import { cors } from "hono/cors"
3+
import { HTTPException } from "hono/http-exception"
34
import { logger } from "hono/logger"
45

56
import { state } from "./lib/state"
@@ -37,6 +38,26 @@ export const server = new Hono()
3738
server.use(logger())
3839
server.use(cors())
3940

41+
// Global error handler
42+
server.onError((err, c) => {
43+
if (err instanceof HTTPException) {
44+
return c.json(
45+
{
46+
error: err.message,
47+
},
48+
err.status,
49+
)
50+
}
51+
52+
console.error("Unhandled error:", err)
53+
return c.json(
54+
{
55+
error: "Internal server error",
56+
},
57+
500,
58+
)
59+
})
60+
4061
server.get("/", (c) => {
4162
if (state.serverStartTime) {
4263
const uptime = Date.now() - state.serverStartTime

0 commit comments

Comments
 (0)