mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 11:04:02 +03:00
Preserve exception messages for wrapped Django exceptions (#8051)
* Preserve messages for wrapped Django exceptions * Fix the test * Update test_generics.py * Update test_generics.py Co-authored-by: Tom Christie <tom@tomchristie.com>
This commit is contained in:
parent
911b207fa1
commit
56946fac8f
|
@ -79,9 +79,9 @@ def exception_handler(exc, context):
|
||||||
to be raised.
|
to be raised.
|
||||||
"""
|
"""
|
||||||
if isinstance(exc, Http404):
|
if isinstance(exc, Http404):
|
||||||
exc = exceptions.NotFound()
|
exc = exceptions.NotFound(*(exc.args))
|
||||||
elif isinstance(exc, PermissionDenied):
|
elif isinstance(exc, PermissionDenied):
|
||||||
exc = exceptions.PermissionDenied()
|
exc = exceptions.PermissionDenied(*(exc.args))
|
||||||
|
|
||||||
if isinstance(exc, exceptions.APIException):
|
if isinstance(exc, exceptions.APIException):
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.shortcuts import get_object_or_404
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from rest_framework import generics, renderers, serializers, status
|
from rest_framework import generics, renderers, serializers, status
|
||||||
|
from rest_framework.exceptions import ErrorDetail
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
from tests.models import (
|
from tests.models import (
|
||||||
|
@ -519,7 +520,12 @@ class TestFilterBackendAppliedToViews(TestCase):
|
||||||
request = factory.get('/1')
|
request = factory.get('/1')
|
||||||
response = instance_view(request, pk=1).render()
|
response = instance_view(request, pk=1).render()
|
||||||
assert response.status_code == status.HTTP_404_NOT_FOUND
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
assert response.data == {'detail': 'Not found.'}
|
assert response.data == {
|
||||||
|
'detail': ErrorDetail(
|
||||||
|
string='No BasicModel matches the given query.',
|
||||||
|
code='not_found'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
def test_get_instance_view_will_return_single_object_when_filter_does_not_exclude_it(self):
|
def test_get_instance_view_will_return_single_object_when_filter_does_not_exclude_it(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user