mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 22:04:48 +03:00
Extract exception handler usage to separate method.
This allow using custom exception handler on view class level, and thus having differently configured APIs in one project. Solves multi-configuration problem for django-rest-framework-json-api that has a custom exception handler that must return jsonapi compatible error response.
This commit is contained in:
parent
95418eb8ac
commit
6c6d926cb3
|
@ -425,10 +425,8 @@ class APIView(View):
|
|||
else:
|
||||
exc.status_code = status.HTTP_403_FORBIDDEN
|
||||
|
||||
exception_handler = self.settings.EXCEPTION_HANDLER
|
||||
|
||||
context = self.get_exception_handler_context()
|
||||
response = exception_handler(exc, context)
|
||||
response = self._get_error_response(exc, context)
|
||||
|
||||
if response is None:
|
||||
raise
|
||||
|
@ -436,6 +434,9 @@ class APIView(View):
|
|||
response.exception = True
|
||||
return response
|
||||
|
||||
def _get_error_response(self, exc, context):
|
||||
return self.settings.EXCEPTION_HANDLER(exc, context)
|
||||
|
||||
# Note: Views are made CSRF exempt from within `as_view` as to prevent
|
||||
# accidental removal of this exemption in cases where `dispatch` needs to
|
||||
# be overridden.
|
||||
|
|
Loading…
Reference in New Issue
Block a user