mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-14 05:36:50 +03:00
add per-view custom exception handler support (#4753)
This commit is contained in:
parent
ecb905267f
commit
ebe174c0d7
|
@ -73,6 +73,8 @@ The following methods are used by REST framework to instantiate the various plug
|
||||||
|
|
||||||
### .get_content_negotiator(self)
|
### .get_content_negotiator(self)
|
||||||
|
|
||||||
|
### .get_exception_handler(self)
|
||||||
|
|
||||||
## API policy implementation methods
|
## API policy implementation methods
|
||||||
|
|
||||||
The following methods are called before dispatching to the handler method.
|
The following methods are called before dispatching to the handler method.
|
||||||
|
|
|
@ -286,6 +286,12 @@ class APIView(View):
|
||||||
self._negotiator = self.content_negotiation_class()
|
self._negotiator = self.content_negotiation_class()
|
||||||
return self._negotiator
|
return self._negotiator
|
||||||
|
|
||||||
|
def get_exception_handler(self):
|
||||||
|
"""
|
||||||
|
Returns the exception handler that this view uses.
|
||||||
|
"""
|
||||||
|
return api_settings.EXCEPTION_HANDLER
|
||||||
|
|
||||||
# API policy implementation methods
|
# API policy implementation methods
|
||||||
|
|
||||||
def perform_content_negotiation(self, request, force=False):
|
def perform_content_negotiation(self, request, force=False):
|
||||||
|
@ -428,7 +434,7 @@ class APIView(View):
|
||||||
else:
|
else:
|
||||||
exc.status_code = status.HTTP_403_FORBIDDEN
|
exc.status_code = status.HTTP_403_FORBIDDEN
|
||||||
|
|
||||||
exception_handler = self.settings.EXCEPTION_HANDLER
|
exception_handler = self.get_exception_handler()
|
||||||
|
|
||||||
context = self.get_exception_handler_context()
|
context = self.get_exception_handler_context()
|
||||||
response = exception_handler(exc, context)
|
response = exception_handler(exc, context)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user