Adding error 503 catcher

This commit is contained in:
Marcus Andersson 2021-05-13 00:08:15 +02:00 committed by Kevin Morris
parent cdf75ced9a
commit f6744d3e39
3 changed files with 16 additions and 2 deletions

View file

@ -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")

View file

@ -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
}

View file

@ -0,0 +1,8 @@
{% extends 'partials/layout.html' %}
{% block pageContent %}
<div class="box 404">
<h2>503 - {% trans %}Service Unavailable{% endtrans %}</h2>
<p>{% trans %}Don't panic! This site is down due to maintenance. We will be back soon.{% endtrans %}</p>
</div>
{% endblock %}