@@ -30,9 +30,27 @@ Might receive an error response indicating that the `DELETE` method is not allow
...
@@ -30,9 +30,27 @@ Might receive an error response indicating that the `DELETE` method is not allow
HTTP/1.1 405 Method Not Allowed
HTTP/1.1 405 Method Not Allowed
Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
Content-Length: 42
Content-Length: 42
{"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:
@@ -25,7 +25,7 @@ If you need to access the values of REST framework's API settings in your projec
...
@@ -25,7 +25,7 @@ If you need to access the values of REST framework's API settings in your projec
you should use the `api_settings` object. For example.
you should use the `api_settings` object. For example.
from rest_framework.settings import api_settings
from rest_framework.settings import api_settings
print api_settings.DEFAULT_AUTHENTICATION_CLASSES
print api_settings.DEFAULT_AUTHENTICATION_CLASSES
The `api_settings` object will check for any user-defined settings, and otherwise fall back to the default values. Any setting that uses string import paths to refer to a class will automatically import and return the referenced class, instead of the string literal.
The `api_settings` object will check for any user-defined settings, and otherwise fall back to the default values. Any setting that uses string import paths to refer to a class will automatically import and return the referenced class, instead of the string literal.
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: