Add basic error pages

This commit is contained in:
Adam Shimali
2016-01-07 15:48:29 +00:00
parent afd03ea5bf
commit d64e3b81fb
4 changed files with 41 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
import os
import re
from flask import Flask, session, Markup
from flask import Flask, session, Markup, render_template
from flask._compat import string_types
from flask.ext.sqlalchemy import SQLAlchemy
from flask_login import LoginManager
@@ -47,6 +47,7 @@ def create_app(config_name):
application.add_template_filter(replace_placeholders)
application.after_request(useful_headers_after_request)
register_errorhandlers(application)
return application
@@ -116,3 +117,12 @@ def useful_headers_after_request(response):
response.headers.add('X-Content-Type-Options', 'nosniff')
response.headers.add('X-XSS-Protection', '1; mode=block')
return response
def register_errorhandlers(app):
def render_error(error):
# If a HTTPException, pull the `code` attribute; default to 500
error_code = getattr(error, 'code', 500)
return render_template("error/{0}.html".format(error_code)), error_code
for errcode in [401, 404, 500]:
app.errorhandler(errcode)(render_error)
return None

View File

@@ -0,0 +1,10 @@
{% extends "admin_template.html" %}
{% block page_title %}Unauthorized{% endblock %}
{% block fullwidth_content %}
<div class="grid-row">
<div class="column-two-thirds">
<h1>401</h1>
<p>You are not authorized to see this page.</p>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,10 @@
{% extends "admin_template.html" %}
{% block page_title %}Page Not Found{% endblock %}
{% block fullwidth_content %}
<div class="grid-row">
<div class="column-two-thirds">
<h1>404</h1>
<p>Sorry, that page doesn't exist.</p>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,10 @@
{% extends "admin_template.html" %}
{% block page_title %}Server error{% endblock %}
{% block fullwidth_content %}
<div class="grid-row">
<div class="column-two-thirds">
<h1>500</h1>
<p>Sorry, something went wrong on our system.</p>
</div>
</div>
{% endblock %}