Overriding details in custom example for unexpected error #18
-
|
https://github.com/NRWLDev/fastapi-problem/blob/main/examples/custom.py In the custom example for an unexpected error, is it possible to override |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
The simplest way is to add a try/except at the location that the error can occur, and raise a Problem with the details you would like. The title is the more appropriate location for the generic message you would like, as the details gives a little context as to how the server failed. To change the title of all unhandled server errors change the ServerError title in that example file. The other way if you have a lot of locations where this error can occur is to use a custom handler for the error type and convert the error to a Problem with the details you would like. |
Beta Was this translation helpful? Give feedback.
The simplest way is to add a try/except at the location that the error can occur, and raise a Problem with the details you would like.
The title is the more appropriate location for the generic message you would like, as the details gives a little context as to how the server failed. To change the title of all unhandled server errors change the ServerError title in that example file.
The other way if you have a lot of locations where this error can occur is to use a custom handler for the error type and convert the error to a Problem with the details you would like.
https://nrwldev.github.io/fastapi-problem/handlers/