Skip to content

Commit

Permalink
Add custom error pages for user errors
Browse files Browse the repository at this point in the history
Such as 404. We already have separate handling for
internal errors, and Stac API errors.
  • Loading branch information
jeremyh committed Jan 12, 2022
1 parent 97f17c8 commit 92657af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cubedash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("/<product_name>")
@app.route("/<product_name>/<int:year>")
@app.route("/<product_name>/<int:year>/<int:month>")
Expand Down
19 changes: 19 additions & 0 deletions cubedash/templates/message.html
Original file line number Diff line number Diff line change
@@ -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 %}
<div class="panel highlight">
<h2>{{ title }}</h2>
<p>{{ message }}</p>
</div>
{% endblock %}

0 comments on commit 92657af

Please sign in to comment.