@@ -33,6 +33,24 @@ Might receive an error response indicating that the `DELETE` method is not allow
...
@@ -33,6 +33,24 @@ Might receive an error response indicating that the `DELETE` method is not allow
{"detail": "Method 'DELETE' not allowed."}
{"detail": "Method 'DELETE' not allowed."}
## Custom exception handling
To implement custom exception handling (e.g. to handle additional exception classes or to override the error response format), create an exception handler function with the following signature:
exception_handler(exc)
*`exc`: The exception.
If the function returns `None`, a 500 error will be raised.
The exception handler is set globally, using the `EXCEPTION_HANDLER` setting. For example:
A string representing the function that should be used when returning a response for any given exception. If the function returns `None`, a 500 error will be raised.
This setting can be changed to support error responses other than the default `{"detail": "Failure..."}` responses. For example, you can use it to provide API responses like `{"errors": [{"message": "Failure...", "code": ""} ...]}`.
This should be a function with the following signature: