8000 Add EXCEPTION_HANDLER docs to exception docs · lalkaka/django-rest-framework@bae0ef6 · GitHub
[go: up one dir, main page]

Skip to content

Commit bae0ef6

Browse files
author
Andy Freeland
committed
Add EXCEPTION_HANDLER docs to exception docs
1 parent b5523bc commit bae0ef6

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/api-guide/exceptions.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,27 @@ Might receive an error response indicating that the `DELETE` method is not allow
3030
HTTP/1.1 405 Method Not Allowed
3131
Content-Type: application/json; charset=utf-8
3232
Content-Length: 42
33-
33+
3434
{"detail": "Method 'DELETE' not allowed."}
3535

36+
## Custom exception handling
37+
38+
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:
39+
40+
exception_handler(exc)
41+
42+
* `exc`: The exception.
43+
44+
If the function returns `None`, a 500 error will be raised.
45+
46+
The exception handler is set globally, using the `EXCEPTION_HANDLER` setting. For example:
47+
48+
'EXCEPTION_HANDLER': 'project.app.module.function'
49+
50+
If not specified, this setting defaults to the exception handler described above:
51+
52+
'EXCEPTION_HANDLER': 'rest_framework.views.exception_handler'
53+
3654
---
3755

3856
# API Reference

0 commit comments

Comments
 (0)
0