From c0f479880d700fdaeff894e7fc93c3a4340d15b1 Mon Sep 17 00:00:00 2001 From: Stefano Date: Wed, 13 Sep 2017 09:06:59 +0200 Subject: [PATCH] Add 403, 404 and 500 error handling --- server.py | 15 +++++++++++++++ templates/403.htm | 7 +++++++ templates/404.htm | 7 +++++++ templates/500.htm | 13 +++++++++++++ templates/nav.htm | 2 +- 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 templates/403.htm create mode 100644 templates/404.htm create mode 100644 templates/500.htm diff --git a/server.py b/server.py index 4e5336f..0d1c64b 100644 --- a/server.py +++ b/server.py @@ -673,6 +673,21 @@ def page_smecds(): return render_template("smecds.htm", type="main", user=session["username"]) +@app.errorhandler(403) +def page_403(_): + return render_template('403.htm') + + +@app.errorhandler(404) +def page_404(_): + return render_template('404.htm') + + +@app.errorhandler(500) +def page_500(e): + return render_template('500.htm', e=e) + + if __name__ == "__main__": # Se non esiste il database, crealo e inizializzalo! if not os.path.isfile("data.db"): diff --git a/templates/403.htm b/templates/403.htm new file mode 100644 index 0000000..ebdc556 --- /dev/null +++ b/templates/403.htm @@ -0,0 +1,7 @@ +{% extends 'base.htm' %} +{% block title %}Non autorizzato • estus{% endblock %} +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/templates/404.htm b/templates/404.htm new file mode 100644 index 0000000..be712b9 --- /dev/null +++ b/templates/404.htm @@ -0,0 +1,7 @@ +{% extends 'base.htm' %} +{% block title %}Non trovato • estus{% endblock %} +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/templates/500.htm b/templates/500.htm new file mode 100644 index 0000000..55f301d --- /dev/null +++ b/templates/500.htm @@ -0,0 +1,13 @@ +{% extends 'base.htm' %} +{% block title %}Errore server • estus{% endblock %} +{% block content %} + +
+ Ecco una piccola descrizione dell'errore... +
+ + {{ e }} + +{% endblock %} \ No newline at end of file diff --git a/templates/nav.htm b/templates/nav.htm index 359eaa0..d1c0666 100644 --- a/templates/nav.htm +++ b/templates/nav.htm @@ -22,6 +22,6 @@ Logout - {% endif %} + {% endif %}