-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror_handler.py
More file actions
24 lines (17 loc) · 837 Bytes
/
error_handler.py
File metadata and controls
24 lines (17 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import logging
import traceback
from flask import make_response
from flask.typing import ResponseReturnValue
from werkzeug.exceptions import HTTPException
from eligibility_signposting_api.api_error_response import INTERNAL_SERVER_ERROR
logger = logging.getLogger(__name__)
def handle_exception(e: Exception) -> ResponseReturnValue | HTTPException:
logger.exception("Unexpected Exception", exc_info=e)
# Let Flask handle its own exceptions for now.
if isinstance(e, HTTPException):
return e
full_traceback = "".join(traceback.format_exception(e))
response = INTERNAL_SERVER_ERROR.log_and_generate_response(
log_message=f"An unexpected error occurred: {full_traceback}", diagnostics="An unexpected error occurred."
)
return make_response(response.get("body"), response.get("statusCode"))