From 92657af998b4bf304c9c6aa0426f4a4a83bd437c Mon Sep 17 00:00:00 2001 From: Jeremy Hooke Date: Wed, 12 Jan 2022 15:17:48 +1100 Subject: [PATCH] Add custom error pages for user errors Such as 404. We already have separate handling for internal errors, and Stac API errors. --- cubedash/_pages.py | 14 ++++++++++++++ cubedash/templates/message.html | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 cubedash/templates/message.html diff --git a/cubedash/_pages.py b/cubedash/_pages.py index cffc800dc..e38f5d038 100644 --- a/cubedash/_pages.py +++ b/cubedash/_pages.py @@ -10,6 +10,7 @@ from datacube.scripts.dataset import build_dataset_info from flask import abort, redirect, request, url_for from werkzeug.datastructures import MultiDict +from werkzeug.exceptions import HTTPException import cubedash from cubedash import _audit, _monitoring @@ -52,6 +53,19 @@ _monitoring.init_app_monitoring() +@app.errorhandler(HTTPException) +def handle_exception(e: HTTPException): + return ( + utils.render( + "message.html", + title=e.code, + message=e.description, + e=e, + ), + e.code, + ) + + @app.route("/") @app.route("//") @app.route("///") diff --git a/cubedash/templates/message.html b/cubedash/templates/message.html new file mode 100644 index 000000000..47fc981f5 --- /dev/null +++ b/cubedash/templates/message.html @@ -0,0 +1,19 @@ +{% extends "layout/base.html" %} + +{# +A simple page for showing a message to the user. + +Such as a 404. + +#} + +{% set active_page = "message" %} + +{% block title %}{{ title }}: {{ message }}{% endblock %} + +{% block content %} +
+

{{ title }}

+

{{ message }}

+
+{% endblock %}