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

Add context to ErrorHandler #11

Open
pebo opened this issue Feb 9, 2024 · 2 comments · May be fixed by #13
Open

Add context to ErrorHandler #11

pebo opened this issue Feb 9, 2024 · 2 comments · May be fixed by #13

Comments

@pebo
Copy link

pebo commented Feb 9, 2024

In order to correlate custom ErrorHandler logging with requests if would be very helpful if the ErrorHandler signature was expanded to include context.Context e.g.

type ErrorHandler func(ctx context.Context, w http.ResponseWriter, message string, statusCode int)

This however is a breaking change so another option could be to expand Options with a ErrorHandlerWithContext field.

@pebo
Copy link
Author

pebo commented Feb 14, 2024

Added two example PRs for this.

Ran into the missing context when migration to chi from gin which has a context in the validation middleware:

type ErrorHandler func(c *gin.Context, message string, statusCode int)

@mikeschinkel
Copy link

There is definitely a need for more info in the error handler.

Context is one such need, but the current matched Route, the Request, and the Request's Headers — like Accept — are others.

I created a PR (#15) that (I think) addresses @pebo's use-case in this issue but also addresses others, and in a manner that will allow adding other info if such info is found to be needed by others in the future. Hopefully PR #15 can supersede PRs #13 and #14 since they change error handling but don't address the use-cases that #15 address.

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 a pull request may close this issue.

2 participants