diff --git a/app/__init__.py b/app/__init__.py index e32859141..912df90ad 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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 diff --git a/app/templates/error/401.html b/app/templates/error/401.html new file mode 100644 index 000000000..8ea00a7bc --- /dev/null +++ b/app/templates/error/401.html @@ -0,0 +1,10 @@ +{% extends "admin_template.html" %} +{% block page_title %}Unauthorized{% endblock %} +{% block fullwidth_content %} +
+
+

401

+

You are not authorized to see this page.

+
+
+{% endblock %} diff --git a/app/templates/error/404.html b/app/templates/error/404.html new file mode 100644 index 000000000..91a904d7b --- /dev/null +++ b/app/templates/error/404.html @@ -0,0 +1,10 @@ +{% extends "admin_template.html" %} +{% block page_title %}Page Not Found{% endblock %} +{% block fullwidth_content %} +
+
+

404

+

Sorry, that page doesn't exist.

+
+
+{% endblock %} diff --git a/app/templates/error/500.html b/app/templates/error/500.html new file mode 100644 index 000000000..66fd970e4 --- /dev/null +++ b/app/templates/error/500.html @@ -0,0 +1,10 @@ +{% extends "admin_template.html" %} +{% block page_title %}Server error{% endblock %} +{% block fullwidth_content %} +
+
+

500

+

Sorry, something went wrong on our system.

+
+
+{% endblock %}