MCPcopy Index your code
hub / github.com/encode/django-rest-framework / handle_exception

Method handle_exception

rest_framework/views.py:454–478  ·  view source on GitHub ↗

Handle any exception that occurs, by returning an appropriate response, or re-raising the error.

(self, exc)

Source from the content-addressed store, hash-verified

452 return response
453
454 def handle_exception(self, exc):
455 """
456 Handle any exception that occurs, by returning an appropriate response,
457 or re-raising the error.
458 """
459 if isinstance(exc, (exceptions.NotAuthenticated,
460 exceptions.AuthenticationFailed)):
461 # WWW-Authenticate header for 401 responses, else coerce to 403
462 auth_header = self.get_authenticate_header(self.request)
463
464 if auth_header:
465 exc.auth_header = auth_header
466 else:
467 exc.status_code = status.HTTP_403_FORBIDDEN
468
469 exception_handler = self.get_exception_handler()
470
471 context = self.get_exception_handler_context()
472 response = exception_handler(exc, context)
473
474 if response is None:
475 self.raise_uncaught_exception(exc)
476
477 response.exception = True
478 return response
479
480 def raise_uncaught_exception(self, exc):
481 if settings.DEBUG:

Callers 1

dispatchMethod · 0.95

Calls 5

get_exception_handlerMethod · 0.95
exception_handlerFunction · 0.85

Tested by

no test coverage detected