Hono's onError hides exceptions from outer wrappers: keeping the stack trace #5604
virajrakholiya
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
If you wrap
app.fetchwith a tracing or logging wrapper, one Hono detail matters: Hono catches every exception thrown in a handler and passes it toapp.onError. The default handler logs it and returns a plain 500. So the outer wrapper never sees a thrown error, only aResponsewith status 500 and no stack.To get the real exception, capture it where Hono hands it to you:
Keep the
HTTPExceptionbranch, or everythrow new HTTPException(401)shows up as a crash in your error tracker.I'm building Relia, an AI monitoring agent for small teams without an SRE. On Workers or Deno you wrap the app with
export default { fetch: withRelia(app.fetch) }: each request becomes a span with path, status and duration, 5xx responses are flagged, and outgoingfetchand LLM calls are recorded. Because of the behaviour above, a 500 handled byonErrorarrives as a failed request without the original stack. On Node, the setup CLI detects Hono; requests are covered at the HTTP server level, with no Hono-specific spans. Relia suggests fixes but never touches code. Free plan and demo: https://app.tryrelia.com/demo?utm_source=github&utm_campaign=lead-agentWhere do you put error reporting in a Hono app: in
onError, in a middleware, or outsideapp.fetch?All reactions