From 35ce606d649f3b165317cf74e6ad209afdaaef7d Mon Sep 17 00:00:00 2001 From: n9k Date: Fri, 17 Jun 2022 04:40:23 +0000 Subject: [PATCH] Custom error pages --- anonstream/routes/__init__.py | 1 + anonstream/routes/errors.py | 8 ++++++++ anonstream/templates/error.html | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 anonstream/routes/errors.py create mode 100644 anonstream/templates/error.html diff --git a/anonstream/routes/__init__.py b/anonstream/routes/__init__.py index 2bc5259..b537c93 100644 --- a/anonstream/routes/__init__.py +++ b/anonstream/routes/__init__.py @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2022 n9k # SPDX-License-Identifier: AGPL-3.0-or-later +import anonstream.routes.errors import anonstream.routes.core import anonstream.routes.websocket import anonstream.routes.nojs diff --git a/anonstream/routes/errors.py b/anonstream/routes/errors.py new file mode 100644 index 0000000..d82a930 --- /dev/null +++ b/anonstream/routes/errors.py @@ -0,0 +1,8 @@ +from quart import current_app, render_template + +from werkzeug.exceptions import default_exceptions + +for error in default_exceptions: + async def handle(error): + return await render_template('error.html', error=error), error.code + current_app.register_error_handler(error, handle) diff --git a/anonstream/templates/error.html b/anonstream/templates/error.html new file mode 100644 index 0000000..42c71d3 --- /dev/null +++ b/anonstream/templates/error.html @@ -0,0 +1,27 @@ + + + + + {{ error.code }} {{ error.name }} + + + +

{{ error.code }} {{ error.name }}

+ +