List of Django exceptions and response codes
Question:
Certain django exceptions have associated status codes. For example:
- The
SuspiciousOperation
exception returns a 400 if it is raised.
- The
PermissionDenied
exception returns a 403 if it is raised.
- The
Http404
exception returns a 404 status if it is raised.
Where can I find a comprehensive list of this? It is lacking on https://docs.djangoproject.com/en/1.7/ref/exceptions/
Answers:
Those are the only two. Everything else, if it’s not caught, is a 500 status, which is the catch-all “server error” code.
Here are the exception handlers: https://github.com/django/django/blob/1.7/django/core/handlers/base.py#L139. As you can see there are only 3 “named” exceptions catched there (I’m not counting SystemExit
), everything else is handled by handle_uncaught_exception and results in the 500 error.
Certain django exceptions have associated status codes. For example:
- The
SuspiciousOperation
exception returns a 400 if it is raised. - The
PermissionDenied
exception returns a 403 if it is raised. - The
Http404
exception returns a 404 status if it is raised.
Where can I find a comprehensive list of this? It is lacking on https://docs.djangoproject.com/en/1.7/ref/exceptions/
Those are the only two. Everything else, if it’s not caught, is a 500 status, which is the catch-all “server error” code.
Here are the exception handlers: https://github.com/django/django/blob/1.7/django/core/handlers/base.py#L139. As you can see there are only 3 “named” exceptions catched there (I’m not counting SystemExit
), everything else is handled by handle_uncaught_exception and results in the 500 error.