From 75995653444f1efc9efe1ce3050e5d739b47670f Mon Sep 17 00:00:00 2001 From: codl Date: Sun, 10 Sep 2017 13:20:53 +0200 Subject: [PATCH] add proper error pages for 404, 500 --- assets/styles.css | 7 +++++++ routes.py | 11 +++++++++++ templates/404.html | 12 ++++++++++++ templates/500.html | 24 ++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 templates/404.html create mode 100644 templates/500.html diff --git a/assets/styles.css b/assets/styles.css index ce694af..2d455cc 100644 --- a/assets/styles.css +++ b/assets/styles.css @@ -257,3 +257,10 @@ form.btn-group { .clearfix { clear: both; } + +section > pre.error-log { + overflow: auto; + padding-top: 2em; + padding-bottom: 2em; + opacity: 0.7; +} diff --git a/routes.py b/routes.py index a59a503..47ca317 100644 --- a/routes.py +++ b/routes.py @@ -54,6 +54,17 @@ def touch_viewer(resp): return resp +@app.errorhandler(404) +def not_found(e): + return (render_template('404.html', e=e), 404) + + +@app.errorhandler(500) +@app.errorhandler(Exception) +def internal_server_error(e): + return (render_template('500.html', e=e), 500) + + @app.route('/') def index(): if g.viewer: diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..2cf225a --- /dev/null +++ b/templates/404.html @@ -0,0 +1,12 @@ +{% extends 'lib/layout.html' %} + +{% block body -%} +
+

Nothing here

+

It seems you may have gotten lost. Head back

+
+    404 Not Found
+
+    {{e}}
+
+{% endblock %} diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..203189c --- /dev/null +++ b/templates/500.html @@ -0,0 +1,24 @@ +{% extends 'lib/layout.html' %} + +{% block body -%} + +
+

Something unexpected happened!

+

+ {%- if g.sentry_event_id %} + This error has been logged, please try again in a few minutes. + {%- else %} + Please try again in a few minutes. + {%- endif %} +

+
+    500 Internal server error
+
+    {{e}}
+
+    {%- if g.sentry_event_id %}
+    sentry://{{ g.sentry_event_id }}
+    {%- endif %}
+
+ +{%- endblock %}