Skip to content

Commit aa3b545

Browse files
authored
Merge pull request #129 from labthings/reformat-fallback
Nicer formatting of fallback, allow HTML code to be changed from 500
2 parents 7957450 + c0a3eb6 commit aa3b545

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/labthings_fastapi/server/fallback.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ def __init__(self, *args, **kwargs):
1212
self.labthings_server = None
1313
self.labthings_error = None
1414
self.log_history = None
15+
self.html_code = 500
1516

1617

1718
app = FallbackApp()
1819

1920
ERROR_PAGE = """
2021
<!DOCTYPE html>
2122
<html>
22-
<head>
23+
<head lang="en">
2324
<title>LabThings</title>
25+
<style>
26+
pre {
27+
white-space: pre-wrap;
28+
overflow-wrap: anywhere;
29+
}
30+
</style>
2431
</head>
2532
<body>
2633
<h1>LabThings Could't Load</h1>
@@ -44,7 +51,7 @@ def __init__(self, *args, **kwargs):
4451

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

6774
content = content.replace("{{logginginfo}}", logging_info)
68-
return HTMLResponse(content=content, status_code=500)
75+
return HTMLResponse(content=content, status_code=app.html_code)
6976

7077

7178
@app.get("/{path:path}")

0 commit comments

Comments
 (0)