From bc0e994784f46330b4e849c3326fbd5c500298b3 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sat, 21 Dec 2013 21:10:05 +0000 Subject: [PATCH] Added example of using APIException class. Closes #1300 --- docs/api-guide/exceptions.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/api-guide/exceptions.md b/docs/api-guide/exceptions.md index c46d415e4..221df679d 100644 --- a/docs/api-guide/exceptions.md +++ b/docs/api-guide/exceptions.md @@ -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)`