IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit 09db0e85 authored by Emi Simpson's avatar Emi Simpson
Browse files

Added 404 and 500 error pages

parent 6163828e
......@@ -144,6 +144,7 @@ def create_app(test_config: Optional[Dict[str, Any]] = None) -> Flask:
app.config.from_pyfile(config_path)
app.register_blueprint(views.bp)
views.register_error_pages(app)
app.jinja_env.globals.update(uuid=uuid.uuid4)
app.jinja_env.globals.update(high_contrast=is_high_contrast)
app.jinja_env.globals.update(static_versioned=static_versioned)
......
{% extends "base.html" %}
{% import "utils.html" as utils %}
{% block title %} Error {{errno}} — {{short_desc}} {% endblock %}
{% block head %}
{{super()}}
<style>
body {
text-align: center;
display: grid;
grid-template-columns: 1fr auto;
justify-content: center;
}
p {
font-size: 2em;
}
</style>
{% endblock %}
{% block main %}
<h1> Error {{errno}} — {{short_desc}}</h1>
<p>{{long_desc}}</p>
{% endblock %}
......@@ -5,6 +5,8 @@ See individual views below for details on exactly what templates are used, and w
connect up with.
'''
from functools import reduce
from flask.app import Flask
from elasticsearch.client import Elasticsearch
from pymysql.cursors import Cursor
from werkzeug.exceptions import BadRequest, NotFound
......@@ -125,6 +127,39 @@ def post_main() -> str:
flask.flash(e.message, e.category)
return cast(str, main())
def error_404(_: Any) -> Tuple[str, int]:
"""
Render the 404 error page
"""
db = get_database()
with db.cursor() as cursor:
return render_template(
"error.html",
errno = 404,
short_desc = "Page Not Found",
long_desc = "This page doesn't exist! If you're looking for a project, it may have been deleted.",
login = _login_or_profile(cursor)
), 404
def error_500(_: Any) -> Tuple[str, int]:
"""
Render the 500 error page
"""
db = get_database()
with db.cursor() as cursor:
return render_template(
"error.html",
errno = 500,
short_desc = "Server Error",
long_desc = "Something very bad happened, that's not supposed to happen",
login = _login_or_profile(cursor)
), 500
def register_error_pages(app: Flask) -> Flask:
app.register_error_handler(404, error_404)
app.register_error_handler(500, error_500)
return app
def _login_or_profile(c: Cursor) -> Tuple[str, str]:
auth_module = get_auth_module()
user = get_auth_module().check_user(c)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment