Skip to content

Commit

Permalink
Add better error handling for UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nikochiko authored and devxpy committed Oct 28, 2023
1 parent 0110021 commit 64d51af
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
19 changes: 19 additions & 0 deletions routers/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ async def favicon():
return FileResponse("static/favicon.ico")


@app.post("/handleError/")
async def handle_error(request: Request):
context = {"request": request, "settings": settings}

def not_found():
st.html(templates.get_template("errors/404.html").render(**context))

def unknown_error():
st.html(templates.get_template("errors/unknown.html").render(**context))

body = await request.json()

match body["status"]:
case 404:
return st.runner(lambda: page_wrapper(request, not_found))
case _:
return st.runner(lambda: page_wrapper(request, unknown_error))


@app.get("/login/")
def login(request: Request):
if request.user and not request.user.is_anonymous:
Expand Down
11 changes: 0 additions & 11 deletions templates/404.html

This file was deleted.

8 changes: 8 additions & 0 deletions templates/errors/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% block content %}
<div style="text-align: center; margin: 2rem 0;">
<h1>
Oops, we can't find this page!
</h1>
<img src="https://media.tenor.com/IHdlTRsmcS4AAAAC/404.gif" height="404" alt="404">
</div>
{% endblock content %}
8 changes: 8 additions & 0 deletions templates/errors/unknown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% block content %}
<div style="text-align: center; margin: 2rem 0;">
<h1>
Uh oh... Something went wrong
</h1>
<img src="https://media.tenor.com/1Wlr9trTPLwAAAAd/robotically-robot.gif" height="404" alt="404">
</div>
{% endblock %}

0 comments on commit 64d51af

Please sign in to comment.