[QUESTION] Custom response format for validation error
See original GitHub issueHow can I reformat default response for validation errors? I find the default formatting too verbose for my app, and wanted to return errors in different structure.
I thought of adding error handler explicitly for pydantic.ValidationError
but this is ignored as the error is caught before that and handled internally by FastAPI:
Is this possible to override default formatter and handle ValidationError
on my own? I tried to search through issues and docs but couldn’t find anything related.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Laravel Validation Error customise format of the Response
My problem is how to format the response for the form requests, especially when this is not global but done on specific form...
Read more >Changing the error message for "forced responses ...
As they mentioned, you have to go to your Library and create the message(s) first, and then go to Survey Options and tell...
Read more >Set rules for your form - Google Docs Editors Help
Open a form in Google Forms. Add one of the following types of questions: Short answer; Paragraph; Checkboxes. Click More More . Click...
Read more >How to make a custom FormRequest error response in ...
Hello,. I am using FormRequests to validate data, but want to return custom JSON on error. So far I was extending the FormRequest...
Read more >JWT Validation - Custom response message - Microsoft Q&A
But I am looking for information on the error attributes from the policy error message to set the response. For example: The APIM...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Docs builders don’t know about exception overriding. Please add an example this page.
Screenshot
This is supported now in the latest versions. 🎉
You can now add handlers for
RequestValidationError
and get the full PydanticValidationError
: https://fastapi.tiangolo.com/tutorial/handling-errors/#override-request-validation-exceptionsMake sure to update your FastAPI version. The current latest is
0.27.0
.I’ll close this issue now, but feel free to add more comments or create new issues.