bauerji / flask-pydantic

flask extension for integration with the awesome pydantic package
MIT License
352 stars 56 forks source link

allow custom error responses to be generated #56

Closed jcreekmore closed 1 year ago

jcreekmore commented 2 years ago

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.

cardoe commented 2 years ago

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?

sonarcloud[bot] commented 2 years ago

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

jcreekmore commented 2 years ago

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

bauerji commented 1 year ago

Thank you @jcreekmore, released in version 0.11.0