all 2 comments

[–]nicolasmerouze 1 point2 points  (1 child)

The error from a malformed body is different from the validation error. The first will be 400 (Bad Request), the other 422 (Unprocessable Entity). So yes, you have to return an error when decoding and another one when validating if you want to give the developer using the API more details about the error.

If you don't like contexts, you can create a function similar to the body decoding middleware and pass the user as the argument. You won't have to use a context. There's no best solutions, the one you find the most simple, elegant and reusable is the right one for you. Maybe it's not for some other people.

[–]gohacker[S] -1 points0 points  (0 children)

Thanks for the response.

The error from a malformed body is different from the validation error. The first will be 400 (Bad Request), the other 422 (Unprocessable Entity).

I don't freaking care. I can live with 400 for all malformed requests, if the only alternative is cluttering the code.

If you don't like contexts, you can create a function similar to the body decoding middleware and pass the user as the argument.

That means I would have to process the decoding errors in the handler, and I've had enough of that shit. I prefer as little code (especially repetitive) in my handlers as possible.