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
Register logger middleware before errors middleware #16921
Conversation
Hi @goodhoko good idea to change the order. We migrate the code to typescript recently so there is a conflict would you be willing to update your PR ? |
In the examples and project templates the "errors" middleware which turn thrown errors into HTTP responses is registered before the "logger" middleware. This causes any errors thrown in controllers to pierce through the logger middleware resulting in these requests not being logged. Eg. when a controller throws a ValidationError the resulting HTTP 400 request is not logged at all. Change the order of middleware registration so that the logger is 'above' the errors middleware and has a chance to log *all* requests.
9e61041
to
92bb176
Compare
@alexandrebodin There weren't any conflicts with |
Hmmm it seems the failed CI is just some flaky test. Can we rerun it? |
FYI we will need a small migration guide for this in the docs and probably to update the docs middleware section example. |
I don't think that one is you |
ok, is any of this actionable from my side? |
@Boegie19 here is the PR I was talking about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and LGTM
This pr will also fix #13327 |
In the examples and project templates the "errors" middleware which turn thrown errors into HTTP responses is registered before the "logger" middleware. This causes any errors thrown in controllers to pierce through the logger middleware resulting in these requests not being logged. Eg. when a controller throws a ValidationError the resulting HTTP 400 request is not logged at all. Change the order of middleware registration so that the logger is 'above' the errors middleware and has a chance to log *all* requests. Co-authored-by: DMehaffy <derrickmehaffy@gmail.com>
In the examples and project templates the "errors" middleware which turn thrown errors into HTTP responses is registered before the "logger" middleware. This causes any errors thrown in controllers to pierce through the logger middleware resulting in these requests not being logged.
Eg. when a controller throws a ValidationError the resulting HTTP 400 request is not logged at all.
Change the order of middleware registration so that the logger is 'above' the errors middleware and has a chance to log all requests.
The caveat to consider is that with this new order, when the "logger" middleware itself throws, the error won't be handled by the
errors
middleware so the resulting HTTP response may not adhere to the standard otherwise expected.