From 2f9d8540487f1e560b8da83d39e39eaafd4c48c8 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 27 Mar 2018 12:20:03 +0200 Subject: [PATCH] Docs for generic error views. --- docs/api-guide/exceptions.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/api-guide/exceptions.md b/docs/api-guide/exceptions.md index ba3d5af9b..dc1294ff8 100644 --- a/docs/api-guide/exceptions.md +++ b/docs/api-guide/exceptions.md @@ -230,5 +230,32 @@ The generic views use the `raise_exception=True` flag, which means that you can By default this exception results in a response with the HTTP status code "400 Bad Request". + +--- + +# Generic Error Views + +Django REST Framework provides two error views suitable for providing generic JSON `500` Server Error and +`400` Bad Request responses. + +Use these as per [Django's Customizing error views documentation][django-custom-error-views]. + +## `rest_framework.exceptions.server_error` + +Returns a response with status code `500` and `application/json` content type. + +Set as `handler500`: + + handler500 = 'rest_framework.exceptions.server_error' + +## `rest_framework.exceptions.server_error` + +Returns a response with status code `400` and `application/json` content type. + +Set as `handler400`: + + handler400 = 'rest_framework.exceptions.bad_request' + [cite]: https://doughellmann.com/blog/2009/06/19/python-exception-handling-techniques/ [authentication]: authentication.md +[django-custom-error-views]: https://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views