diff --git a/aurweb/asgi.py b/aurweb/asgi.py index b6e15582..c03a00f7 100644 --- a/aurweb/asgi.py +++ b/aurweb/asgi.py @@ -8,12 +8,12 @@ from starlette.middleware.sessions import SessionMiddleware import aurweb.config from aurweb.db import get_engine -from aurweb.routers import html, sso +from aurweb.routers import html, sso, errors routes = set() # Setup the FastAPI app. -app = FastAPI() +app = FastAPI(exception_handlers=errors.exceptions) @app.on_event("startup") diff --git a/aurweb/routers/errors.py b/aurweb/routers/errors.py index 5d4ca4ce..3bdaeb9d 100644 --- a/aurweb/routers/errors.py +++ b/aurweb/routers/errors.py @@ -8,7 +8,13 @@ async def not_found(request, exc): return render_template("errors/404.html", context) +async def service_unavailable(request, exc): + _ = l10n.get_translator_for_request(request) + context = make_context(request, "503 - {_('Service Unavailable')}") + return render_template("errors/503.html", context) + # Maps HTTP errors to functions exceptions = { 404: not_found, + 503: service_unavailable } diff --git a/templates/errors/503.html b/templates/errors/503.html new file mode 100644 index 00000000..d31666a1 --- /dev/null +++ b/templates/errors/503.html @@ -0,0 +1,8 @@ +{% extends 'partials/layout.html' %} + +{% block pageContent %} +
{% trans %}Don't panic! This site is down due to maintenance. We will be back soon.{% endtrans %}
+