flask-pydantic icon indicating copy to clipboard operation
flask-pydantic copied to clipboard

allow custom error responses to be generated

Open jcreekmore opened this issue 2 years ago • 2 comments

By defining a new config value that flask_pydantic looks for (FLASK_PYDANTIC_VALIDATION_ERROR_RAISE), we can support raising an exception when we have a validation error. If that is set and the exception is raised, by default, Flask will respond with a 500 error. However, by coupling that feature with Flask.register_error_handler, the user can catch the thrown exception and return whatever custom error response the user wishes. Fixes https://github.com/bauerji/flask-pydantic/issues/45.

jcreekmore avatar Aug 02 '22 17:08 jcreekmore

This is really a great change. I’ve actually been trying to work around this same issue and this would solve my needs. @bauerji could we get this reviewed and in a release?

cardoe avatar Aug 04 '22 01:08 cardoe

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarcloud[bot] avatar Aug 29 '22 13:08 sonarcloud[bot]

@bauerji is there something else you are looking for on this?

jcreekmore avatar Sep 06 '22 18:09 jcreekmore

Thank you @jcreekmore, released in version 0.11.0

bauerji avatar Sep 25 '22 09:09 bauerji