MCPcopy
hub / github.com/django/django / response_for_exception

Function response_for_exception

django/core/handlers/exception.py:64–160  ·  view source on GitHub ↗
(request, exc)

Source from the content-addressed store, hash-verified

62
63
64def response_for_exception(request, exc):
65 if isinstance(exc, Http404):
66 if settings.DEBUG:
67 response = debug.technical_404_response(request, exc)
68 else:
69 response = get_exception_response(
70 request, get_resolver(get_urlconf()), 404, exc
71 )
72
73 elif isinstance(exc, PermissionDenied):
74 response = get_exception_response(
75 request, get_resolver(get_urlconf()), 403, exc
76 )
77 log_response(
78 "Forbidden (Permission denied): %s",
79 request.path,
80 response=response,
81 request=request,
82 exception=exc,
83 )
84
85 elif isinstance(exc, MultiPartParserError):
86 response = get_exception_response(
87 request, get_resolver(get_urlconf()), 400, exc
88 )
89 log_response(
90 "Bad request (Unable to parse request body): %s",
91 request.path,
92 response=response,
93 request=request,
94 exception=exc,
95 )
96
97 elif isinstance(exc, BadRequest):
98 if settings.DEBUG:
99 response = debug.technical_500_response(
100 request, *sys.exc_info(), status_code=400
101 )
102 else:
103 response = get_exception_response(
104 request, get_resolver(get_urlconf()), 400, exc
105 )
106 log_response(
107 "%s: %s",
108 str(exc),
109 request.path,
110 response=response,
111 request=request,
112 exception=exc,
113 )
114 elif isinstance(exc, SuspiciousOperation):
115 if isinstance(exc, (RequestDataTooBig, TooManyFieldsSent, TooManyFilesSent)):
116 # POST data can't be accessed again, otherwise the original
117 # exception would be raised.
118 request._mark_post_parse_error()
119
120 if settings.DEBUG:
121 response = debug.technical_500_response(

Callers 2

get_responseMethod · 0.90
innerFunction · 0.85

Calls 9

get_resolverFunction · 0.90
get_urlconfFunction · 0.90
log_responseFunction · 0.90
get_exception_responseFunction · 0.85
callableFunction · 0.85
sendMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected