Skip to content

Commit

Permalink
fix exceptions to not be masked as 500 on every thrown exception
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipNikolovski committed Dec 10, 2024
1 parent b941569 commit c44244c
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,21 @@ def process_response(self, req, resp, resource, req_succeeded=None): # pylint:d
if resource is None:
status = "404"
else:
exc_type, exc = None, None
if _ENVIRON_EXC in req.env:
exc = req.env[_ENVIRON_EXC]
exc_type = type(exc)
else:
exc_type, exc = None, None

if exc_type and not req_succeeded:
if "HTTPNotFound" in exc_type.__name__:
status = "404"
elif isinstance(exc, falcon.HTTPError) or isinstance(
exc, falcon.HTTPStatus
):
try:
status = exc.title.split(" ")[0]
except ValueError:
status = "500"
else:
status = "500"

Expand Down

0 comments on commit c44244c

Please sign in to comment.