mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-24 00:04:16 +03:00
Merge pull request #1404 from hassanshamim/update-exeptions-documentation
Update Exceptions Documentation
This commit is contained in:
commit
ac1ea5e651
|
@ -18,7 +18,7 @@ The handled exceptions are:
|
||||||
|
|
||||||
In each case, REST framework will return a response with an appropriate status code and content-type. The body of the response will include any additional details regarding the nature of the error.
|
In each case, REST framework will return a response with an appropriate status code and content-type. The body of the response will include any additional details regarding the nature of the error.
|
||||||
|
|
||||||
By default all error responses will include a key `details` in the body of the response, but other keys may also be included.
|
By default all error responses will include a key `detail` in the body of the response, but other keys may also be included.
|
||||||
|
|
||||||
For example, the following request:
|
For example, the following request:
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ Note that the exception handler will only be called for responses generated by r
|
||||||
|
|
||||||
The **base class** for all exceptions raised inside REST framework.
|
The **base class** for all exceptions raised inside REST framework.
|
||||||
|
|
||||||
To provide a custom exception, subclass `APIException` and set the `.status_code` and `.detail` properties on the class.
|
To provide a custom exception, subclass `APIException` and set the `.status_code` and `.default_detail` properties on the class.
|
||||||
|
|
||||||
For example, if your API relies on a third party service that may sometimes be unreachable, you might want to implement an exception for the "503 Service Unavailable" HTTP response code. You could do this like so:
|
For example, if your API relies on a third party service that may sometimes be unreachable, you might want to implement an exception for the "503 Service Unavailable" HTTP response code. You could do this like so:
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ import math
|
||||||
class APIException(Exception):
|
class APIException(Exception):
|
||||||
"""
|
"""
|
||||||
Base class for REST framework exceptions.
|
Base class for REST framework exceptions.
|
||||||
Subclasses should provide `.status_code` and `.detail` properties.
|
Subclasses should provide `.status_code` and `.default_detail` properties.
|
||||||
"""
|
"""
|
||||||
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
default_detail = ''
|
default_detail = ''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user