Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/labthings_fastapi/server/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
self.labthings_server = None
self.labthings_error = None
self.log_history = None
self.html_code = 500


app = FallbackApp()

ERROR_PAGE = """
<!DOCTYPE html>
<html>
<head>
<head lang="en">
<title>LabThings</title>
<style>
pre {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
</style>
</head>
<body>
<h1>LabThings Could't Load</h1>
Expand All @@ -44,7 +51,7 @@

@app.get("/")
async def root():
error_message = f"{app.labthings_error!r}"
error_message = f"{app.labthings_error}"
# use traceback.format_exception to get full traceback as list
# this ends in newlines, but needs joining to be a single string
error_w_trace = "".join(format_exception(app.labthings_error))
Expand All @@ -65,9 +72,9 @@
logging_info = f" <p>Logging info</p>\n <pre>{app.log_history}</pre>"

content = content.replace("{{logginginfo}}", logging_info)
return HTMLResponse(content=content, status_code=500)
return HTMLResponse(content=content, status_code=app.html_code)


@app.get("/{path:path}")
async def redirect_to_root(path: str):
return RedirectResponse(url="/")

Check warning on line 80 in src/labthings_fastapi/server/fallback.py

View workflow job for this annotation

GitHub Actions / coverage

80 line is not covered with tests