Maillol / aiohttp-pydantic

Aiohttp View that validates request body and query sting regarding the annotations declared in the View method
MIT License
67 stars 21 forks source link

400 instead of 422 #18

Closed romkazor closed 3 years ago

romkazor commented 3 years ago

When pydantic validation failed (post request), automatic 400 raise instead 422. How can we include 422 default sheme validation in oas or other user schemas?!

Maillol commented 3 years ago

Currently is not possible to custom the error status code. And IMHO if a pydantic validation failed 400 is more appropriate. If you really want always return a 422 instead of 400, you can monkey patch aiohttp_pydantic.view.inject_params. I will provide a way to trigger a pydantic validation error and return a custom response.

Maillol commented 3 years ago

Done in version 1.10.0 See documentation https://github.com/Maillol/aiohttp-pydantic/#custom-validation-error for details