diff options
| author | Tom Christie | 2014-09-08 14:24:05 +0100 |
|---|---|---|
| committer | Tom Christie | 2014-09-08 14:24:05 +0100 |
| commit | 21980b800d04a1d82a6003823abfdf4ab80ae979 (patch) | |
| tree | d17ea3820d51028b03ab2ed63051d17bf4d55448 /rest_framework/views.py | |
| parent | d934824bff21e4a11226af61efba319be227f4f0 (diff) | |
| download | django-rest-framework-21980b800d04a1d82a6003823abfdf4ab80ae979.tar.bz2 | |
More test sorting
Diffstat (limited to 'rest_framework/views.py')
| -rw-r--r-- | rest_framework/views.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/rest_framework/views.py b/rest_framework/views.py index 23df3443..079e9285 100644 --- a/rest_framework/views.py +++ b/rest_framework/views.py @@ -3,7 +3,7 @@ Provides an APIView class that is the base of all views in REST framework. """ from __future__ import unicode_literals -from django.core.exceptions import PermissionDenied +from django.core.exceptions import PermissionDenied, ValidationError from django.http import Http404 from django.utils.datastructures import SortedDict from django.views.decorators.csrf import csrf_exempt @@ -51,7 +51,8 @@ def exception_handler(exc): Returns the response that should be used for any given exception. By default we handle the REST framework `APIException`, and also - Django's builtin `Http404` and `PermissionDenied` exceptions. + Django's built-in `ValidationError`, `Http404` and `PermissionDenied` + exceptions. Any unhandled exceptions may return `None`, which will cause a 500 error to be raised. @@ -68,6 +69,10 @@ def exception_handler(exc): status=exc.status_code, headers=headers) + elif isinstance(exc, ValidationError): + return Response(exc.message_dict, + status=status.HTTP_400_BAD_REQUEST) + elif isinstance(exc, Http404): return Response({'detail': 'Not found'}, status=status.HTTP_404_NOT_FOUND) |
