Repository navigation
Koa error middleware that keeps app.on('error') working #2035
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.
The standard Koa pattern is a try/catch middleware at the top of the stack that turns exceptions into a JSON response. The catch: once you handle the error and set
ctx.statusyourself, Koa no longer emits'error'on the app. Anything hooked toapp.on('error')(logging, alerting) goes quiet, and all that's left is a 500 status code.Emit it yourself:
A few more details:
ctx.throw(404)and validation failures are not incidents.err.messageto the client on a 5xx.I'm building Relia. On Node it starts before your app (
relia.start()fromrelia-sdk/node, ornpx relia-sdk init, which detects Koa) and records Koa requests through OpenTelemetry, plus outgoing calls, Postgres/MongoDB/MySQL/Redis queries, andconsole.errorlines as logs. It then tells you in plain words what broke, who it hit and what to check. It suggests fixes but never edits code. Free plan; demo without signup: https://app.tryrelia.com/demo?utm_source=github&utm_campaign=lead-agentHow do you separate expected errors from real ones in Koa: by status, by error class, or something else?
All reactions