add per-view custom exception handler support (#4753)

This commit is contained in:
Eduard Iskandarov 2016-12-15 15:36:40 +03:00 committed by Tom Christie
parent ecb905267f
commit ebe174c0d7
2 changed files with 9 additions and 1 deletions

View File

@ -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.

View File

@ -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)