diff options
| author | Tom Christie | 2015-01-19 15:23:08 +0000 |
|---|---|---|
| committer | Tom Christie | 2015-01-19 15:23:08 +0000 |
| commit | e5b94f7b7bbf2f6f35c5e33fb2723bdb0d33bad3 (patch) | |
| tree | a156a4a29a26540c52e5580ffa555b14d6c63fbe /docs/api-guide/exceptions.md | |
| parent | dbb684117f6fe0f9c34f98d5e914fc106090cdbc (diff) | |
| parent | 3cc39ffbceffc5fdbb511d9a10e7732329e8baa4 (diff) | |
| download | django-rest-framework-e5b94f7b7bbf2f6f35c5e33fb2723bdb0d33bad3.tar.bz2 | |
Merge branch 'version-3.1' into cursor-pagination
Diffstat (limited to 'docs/api-guide/exceptions.md')
| -rw-r--r-- | docs/api-guide/exceptions.md | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/docs/api-guide/exceptions.md b/docs/api-guide/exceptions.md index 50bd14dd..56811ec3 100644 --- a/docs/api-guide/exceptions.md +++ b/docs/api-guide/exceptions.md @@ -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. -By default all error responses will include a key `detail` in the body of the response, but other keys may also be included. +Most error responses will include a key `detail` in the body of the response. For example, the following request: @@ -33,6 +33,16 @@ Might receive an error response indicating that the `DELETE` method is not allow {"detail": "Method 'DELETE' not allowed."} +Validation errors are handled slightly differently, and will include the field names as the keys in the response. If the validation error was not specific to a particular field then it will use the "non_field_errors" key, or whatever string value has been set for the `NON_FIELD_ERRORS_KEY` setting. + +Any example validation error might look like this: + + HTTP/1.1 400 Bad Request + Content-Type: application/json + Content-Length: 94 + + {"amount": ["A valid integer is required."], "description": ["This field may not be blank."]} + ## Custom exception handling You can implement custom exception handling by creating a handler function that converts exceptions raised in your API views into response objects. This allows you to control the style of error responses used by your API. |
