add proper error pages for 404, 500

This commit is contained in:
codl 2017-09-10 13:20:53 +02:00
parent fcabf262c5
commit 7599565344
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 54 additions and 0 deletions

View File

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

View File

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

12
templates/404.html Normal file
View File

@ -0,0 +1,12 @@
{% extends 'lib/layout.html' %}
{% block body -%}
<section>
<h2>Nothing here</h2>
<p>It seems you may have gotten lost. <a href='/'>Head back</a></p>
<pre class='error-log'>
404 Not Found
{{e}}</pre>
</section>
{% endblock %}

24
templates/500.html Normal file
View File

@ -0,0 +1,24 @@
{% extends 'lib/layout.html' %}
{% block body -%}
<section>
<h2>Something unexpected happened!</h2>
<p>
{%- 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 %}
</p>
<pre class='error-log'>
500 Internal server error
{{e}}
{%- if g.sentry_event_id %}
sentry://{{ g.sentry_event_id }}
{%- endif %}</pre>
</section>
{%- endblock %}