-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors passed to next are not mapped #7
Comments
Makes sense. Would you mind sending a PR? |
Definitely. This will be a breaking change the if implemented as above. Is that fine, or would you want to keep compatibility? |
The reason why we didn't choose the 4-parameter error callback is that we've often seen loggers being registered using last I think we should handle this in some way. |
Ok, I re-read your comment and I think I was right earlier. This seems in line with the express docs. The global logger must simply pass on the error and the server.use(function logErrors (err, req, res, next) {
console.error(err.stack)
next(err)
})
server.use(HttpProblemResponse({strategy})) |
Ok, I think we should use the 4-parameter error callback and add your sample to the docs. |
About the docs. I notice that they instruct to implement a |
so that it can also handle any caught exception and intercept calls to `next(err)` fixes PDMLab#7
Yes, you're right. I guess it's a copy/paste failure from the |
Current
Express has a built-in way for returning errors from any middleware with the
next(error)
call. It appears that errors returned this way do not get converted intoproblem+json
because the handler is an ordinary middleware callback.Desired
Any error returned in the standard way should be intercepted and converted into a mapped problem document.
Proposal
I think that following best practices of express, the 4-parameter error callback could be used instead. Thus the code can actually be simplified. Here's my implementation:
The only difference is that it must be the last
app.use
call when setting up expressThe text was updated successfully, but these errors were encountered: