Is there any way to map an exception to an HttpResponse object in django?
For example, I would like to map my own “UnauthorizedException” to an HttpResponseForbidden response object so when my view raises that exception, rather than automatically getting mapped to a 500, certain exceptions could be treated as 401.
You can, if you implement your own middleware that implements the
process_exceptionmethod. A quick example: