Skip to content
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

Merged
merged 2 commits into from Dec 5, 2023

Conversation

goodhoko
Copy link
Contributor

@goodhoko goodhoko commented Jun 5, 2023

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.

@innerdvations innerdvations added source: core:strapi Source is core/strapi package pr: fix This PR is fixing a bug labels Jun 26, 2023
@alexandrebodin
Copy link
Member

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.
@goodhoko
Copy link
Contributor Author

goodhoko commented Nov 8, 2023

@alexandrebodin There weren't any conflicts with main but I rebased anyway. Is it good to go?

@goodhoko
Copy link
Contributor Author

Hmmm it seems the failed CI is just some flaky test. Can we rerun it?

@derrickmehaffy
Copy link
Member

derrickmehaffy commented Nov 14, 2023

FYI we will need a small migration guide for this in the docs and probably to update the docs middleware section example.

@derrickmehaffy
Copy link
Member

Hmmm it seems the failed CI is just some flaky test. Can we rerun it?

I don't think that one is you

@goodhoko
Copy link
Contributor Author

ok, is any of this actionable from my side?

@derrickmehaffy
Copy link
Member

@Boegie19 here is the PR I was talking about

Copy link
Member

@derrickmehaffy derrickmehaffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM

@Boegie19
Copy link
Collaborator

This pr will also fix #13327

@Feranchz Feranchz added this to the 4.15.6 milestone Dec 5, 2023
@Feranchz Feranchz merged commit 5fc7637 into strapi:main Dec 5, 2023
90 checks passed
L-Weisz pushed a commit to L-Weisz/strapi that referenced this pull request Jan 9, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:strapi Source is core/strapi package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants