-
Notifications
You must be signed in to change notification settings - Fork 5
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
Consider rfc7807 error response handling #6
Comments
If there was an easy way to take over the default error handler. Maybe something similar to panic handler? |
An error handler is a great idea. I've been working on decoupling the handler from the config though as handlers that were wrapped in middleware were panicking, due to the config not getting set so I'm not sure how one would make the error bubble up to A workaround might be to either use the panic handler, or setting the response type to |
The thing is that we then lose the encoding of different formats. I'm thinking maybe just implement the marshaler types in the error and then in error encoding check if it implements marshaler before using default marshaling. So to have a custom error that works in all formats you'd implement encoding.TextMarshaler, JSON.Marshaler, XML.Marshaler and yaml.Marshaler. You'd probably also want to implement don.StatusCoder to give it a custom status code. I think the simplest way to achieve all of this would be having a StructuredError helper function which you can just pass a struct and a status code to. |
By the way I noticed you're still working on the previous version of Don. I migrated it from standard net/http to using valyala/fasthttp after running some benchmarks and seeing the latter was 10x faster. |
I went back and forked from net/http as we don't (yet) need the performance of fasthttp. The fasthttp change requires us to wrap/update all our middleware. |
It appears don will fallback to a 500 error and uses a simple format
{ "message": "Internal Server Error" }
It would be nice if it used a standard response format with a method of hooking in validation errors like shown in the spec.
Full example below
The text was updated successfully, but these errors were encountered: