Skip to content

Commit 34e13b0

Browse files
RamZallanliam-middlebrook
authored andcommitted
Added a better, prettier error page
1 parent 6abd03b commit 34e13b0

File tree

5 files changed

+81
-2
lines changed

5 files changed

+81
-2
lines changed

conditional/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import subprocess
3-
from flask import Flask
4-
from flask import redirect
3+
from flask import Flask, redirect, request
54
from flask_sqlalchemy import SQLAlchemy
65
from flask_migrate import Migrate
76
from csh_ldap import CSHLDAP
@@ -52,6 +51,8 @@
5251
app.register_blueprint(slideshow_bp)
5352
app.register_blueprint(cache_bp)
5453

54+
from conditional.util.flask import render_template
55+
from conditional.util.ldap import ldap_get_member
5556

5657
@app.route('/<path:path>')
5758
def static_proxy(path):
@@ -63,6 +64,20 @@ def static_proxy(path):
6364
def default_route():
6465
return redirect('/dashboard')
6566

67+
@app.errorhandler(404)
68+
@app.errorhandler(500)
69+
def route_errors(error):
70+
username = request.headers.get('x-webauth-user')
71+
member = ldap_get_member(username)
72+
data = dict()
73+
data['username'] = member.uid
74+
data['name'] = member.cn
75+
code = error.code
76+
return render_template(request=request,
77+
template_name='404.html',
78+
error=str(error),
79+
error_code=code,
80+
**data), 404
6681

6782
@app.cli.command()
6883
def zoo():

conditional/templates/404.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "nav.html" %}
2+
{% block title %}
3+
{{ error_code }}
4+
{% endblock %}
5+
{% block body %}
6+
<div class="container main error-page align-center">
7+
<div class="col-xs-12">
8+
<img src="/static/images/material_attention.svg" alt="Attention!">
9+
<h1>Congratulations or I'm Sorry...</h1>
10+
<h2>Something has gone terribly wrong!</h2>
11+
<h3>The following error has been reported:</h3>
12+
<p>{{ error }}</p>
13+
</div>
14+
</div>
15+
{% endblock %}
Lines changed: 12 additions & 0 deletions
Loading

frontend/stylesheets/app.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
@import 'pages/management';
2626
@import 'pages/hm-attendance';
2727
@import 'pages/attendance-hist';
28+
@import 'pages/errors';
2829
@import 'components/reveal';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.error-page {
2+
padding-top: 80px;
3+
4+
.glyphicon,
5+
h1,
6+
h2,
7+
h3,
8+
p {
9+
color: #878787;
10+
}
11+
12+
img {
13+
margin-bottom: 40px;
14+
width: 200px;
15+
}
16+
17+
h1 {
18+
font-size: 50px;
19+
font-weight: bolder;
20+
}
21+
22+
h2 {
23+
margin-bottom: 80px;
24+
font-size: 30px;
25+
}
26+
27+
h3 {
28+
margin: 0;
29+
font-size: 25px;
30+
}
31+
32+
p {
33+
font-size: 20px;
34+
font-weight: lighter;
35+
}
36+
}

0 commit comments

Comments
 (0)