mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Added example of using APIException class. Closes #1300
This commit is contained in:
parent
1f3ded4559
commit
bc0e994784
|
@ -88,6 +88,14 @@ 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.
|
||||
|
||||
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:
|
||||
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
class ServiceUnavailable(APIException):
|
||||
status_code = 503
|
||||
detail = 'Service temporarily unavailable, try again later.'
|
||||
|
||||
## ParseError
|
||||
|
||||
**Signature:** `ParseError(detail=None)`
|
||||
|
|
Loading…
Reference in New Issue
Block a user