Handle any exception that occurs, by returning an appropriate response, or re-raising the error.
(self, exc)
| 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: |
no test coverage detected