Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom error responses to be generated #56

Merged
merged 2 commits into from Sep 25, 2022

Conversation

jcreekmore
Copy link
Contributor

@jcreekmore jcreekmore commented Aug 2, 2022

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 #45.

When trying to figure out how to test for a feature using the flask
config object as a parameter, I couldn't find a test for this feature
flag being used, so I went ahead and added one.
@cardoe
Copy link
Contributor

cardoe commented Aug 4, 2022

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?

Copy link
Owner

@bauerji bauerji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution. I just a have two small comments to you changes. Can you please have a look?

tests/func/test_app.py Outdated Show resolved Hide resolved
flask_pydantic/core.py Outdated Show resolved Hide resolved
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 bauerji#45.
@sonarcloud
Copy link

sonarcloud bot commented Aug 29, 2022

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
Copy link
Contributor Author

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

@bauerji bauerji merged commit 3e5e7b2 into bauerji:master Sep 25, 2022
@bauerji
Copy link
Owner

bauerji commented Sep 25, 2022

Thank you @jcreekmore, released in version 0.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there any way to make custom response?
3 participants