oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Make OpenAPI Validator `ErrorHandler` take an `error` not a `message`

Open jamietanna opened this issue 3 years ago • 1 comments

When writing handler functions for the OpenAPI Validation Middleware, it's a little odd that we get i.e.:

api.GorillaServerOptions{
		ErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {

But then we only receive the message in the top-level Options: https://github.com/deepmap/oapi-codegen/blob/9a9e66fe11c82b21732777233127d518ad092481/pkg/chi-middleware/oapi_validate.go#L19-L20

We should modify it to provide the full error, then it can be i.e. shipped to a logging platform as-is, with information about what the error type is.

This would be a breaking change, so it'd be best to be a new method, and then we can deprecate the message-only version.

jamietanna avatar Jun 21 '22 16:06 jamietanna

It could be useful to provide the request as well. I need to use request.Context().

MateusFrFreitas avatar Sep 21 '22 19:09 MateusFrFreitas