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

fix(server): log thrown errors #3072

Merged
merged 3 commits into from
Sep 25, 2024
Merged

Conversation

iainsproat
Copy link
Contributor

@iainsproat iainsproat commented Sep 23, 2024

Description & motivation

The default error handler for express was not logging thrown errors. Requests which incurred internal errors had their responses logged as 500 errors without any corresponding error message or stacktrace. This made investigating errors difficult.

This PR amends the default error handler to add the error it is handling to the request context.
The request context is then used by the pino http logger and any included error is logged.

Changes:

  • request.context.err is populated if express server encounters an error
  • pino http logger includes request.context.err in the logged properties.

To-do before merge:

Screenshots:

Validation of changes:

Checklist:

  • My pull request follows the guidelines in the Contributing guide?
  • My pull request does not duplicate any other open Pull Requests for the same update/change?
  • My commits are related to the pull request and do not amend unrelated code or documentation.
  • My code follows a similar style to existing code.
  • I have added appropriate tests.
  • I have updated or added relevant documentation.

References

@iainsproat iainsproat marked this pull request as ready for review September 23, 2024 11:11
@gjedlicska gjedlicska merged commit 0c9aba6 into main Sep 25, 2024
23 of 25 checks passed
@gjedlicska gjedlicska deleted the iain/express-log-thrown-errors branch September 25, 2024 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants