-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
import logging | ||
|
||
from fastapi.templating import Jinja2Templates | ||
from importlib import resources | ||
|
||
from fastapi.requests import Request | ||
|
||
templates = Jinja2Templates(directory=str(resources.path("medperf.web_ui", "templates"))) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
async def custom_exception_handler(request: Request, exc: Exception): | ||
# Log the exception details | ||
logger.error(f"Unhandled exception: {exc}", exc_info=True) | ||
|
||
# Prepare the context for the error page | ||
context = {"request": request, "exception": exc} | ||
|
||
# Return a detailed error page | ||
return templates.TemplateResponse("error.html", context, status_code=500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Error{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<h1 class="my-4">An Error Occurred</h1> | ||
<div class="alert alert-danger" role="alert"> | ||
<p><strong>Error:</strong> {{ exception }}</p> | ||
<p><strong>Request:</strong> {{ request.url }}</p> | ||
<p><strong>Method:</strong> {{ request.method }}</p> | ||
<p><strong>Client:</strong> {{ request.client }}</p> | ||
</div> | ||
</div> | ||
{% endblock %} |