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

feat(web): Add a custom error handler to gokit #16

Merged
merged 1 commit into from Feb 6, 2023

Conversation

javorszky
Copy link
Contributor

Closes #15

Custom error handler that's a literal copy of echo's current built in error handler with two changes. The changes will be pointed out in code comments.


ll.Err(err).
Str("requestID", c.Request().Header.Get(echo.HeaderXRequestID)).
Msg("request returned an error")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change 1 is here. Regardless of what the error is, it needs to be logged. The logger on line 54 would log the error that gets returned from c.JSON or c.NoContent.

if c.Echo().Debug {
message = echo.Map{"code": code, "message": m, "error": err.Error()}
} else {
message = echo.Map{"code": code, "message": m}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change 2 is here. The "code": code, was added to both messages.

See original: https://github.com/labstack/echo/blob/82a964c657e26b68998393d3e7291f1a474447f8/echo.go#L414-L416

@javorszky javorszky merged commit 265d2bb into main Feb 6, 2023
@javorszky javorszky deleted the gabor/15-echo-error-handler branch February 6, 2023 12:34
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.

Add custom echo error handler
2 participants