File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 11import { Hono } from "hono"
22import { cors } from "hono/cors"
3+ import { HTTPException } from "hono/http-exception"
34import { logger } from "hono/logger"
45
56import { state } from "./lib/state"
@@ -37,6 +38,26 @@ export const server = new Hono()
3738server . use ( logger ( ) )
3839server . 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+
4061server . get ( "/" , ( c ) => {
4162 if ( state . serverStartTime ) {
4263 const uptime = Date . now ( ) - state . serverStartTime
You can’t perform that action at this time.
0 commit comments