From 2a3d07d9d3b8ca0ff8e6b142eb3d68097d67df21 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 10 Oct 2016 20:38:43 +0100 Subject: [PATCH] Docstrings --- docs/api-guide/exceptions.md | 2 +- rest_framework/exceptions.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/api-guide/exceptions.md b/docs/api-guide/exceptions.md index 3e4b3e8be..d0dda070f 100644 --- a/docs/api-guide/exceptions.md +++ b/docs/api-guide/exceptions.md @@ -182,7 +182,7 @@ By default this exception results in a response with the HTTP status code "429 T ## ValidationError -**Signature:** `ValidationError(detail)` +**Signature:** `ValidationError(detail, code=None)` The `ValidationError` exception is slightly different from the other `APIException` classes: diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index f7c0048e8..a76e493c7 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -119,9 +119,19 @@ class ValidationError(APIException): return six.text_type(self.detail) def get_codes(self): + """ + Return only the code part of the error details. + + Eg. {"name": ["required"]} + """ return _get_codes(self.detail) def get_full_details(self): + """ + Return both the message & code parts of the error details. + + Eg. {"name": [{"message": "This field is required.", "code": "required"}]} + """ return _get_full_details(self.detail)