From b6ed78c8adb13dcdc1e0a7911aef4e1a46385af5 Mon Sep 17 00:00:00 2001 From: xemeds Date: Mon, 20 Jul 2020 17:51:52 +0000 Subject: [PATCH] Added error handlers --- tiny0/database.db | Bin 12288 -> 12288 bytes tiny0/routes.py | 12 +++++++++++- tiny0/static/style.css | 15 ++++++++++----- tiny0/templates/error.html | 13 +++++++++++++ tiny0/templates/index.html | 2 +- 5 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 tiny0/templates/error.html diff --git a/tiny0/database.db b/tiny0/database.db index ef1ce4c9df39fe68c4d66aebc55a408216cfa7fe..eaf63e081270bdeb41d6bb4a179e38c31ea494a2 100644 GIT binary patch delta 33 gcmZojXh@hKEvU=Dz`zW|Fd#co$Cy!fW5NP`0APLv$N&HU delta 33 gcmZojXh@hKEvUi3z`zW|Fd#Ki$Cy!LW5NP`0AIxgy8r+H diff --git a/tiny0/routes.py b/tiny0/routes.py index 3aa8764..d59e19d 100644 --- a/tiny0/routes.py +++ b/tiny0/routes.py @@ -41,4 +41,14 @@ def short_url(token): # Else if the query response contained data else: # Redirect to the url of the token - return redirect(query.url) \ No newline at end of file + return redirect(query.url) + + +# Error handling routes +@app.errorhandler(404) +def error_404(error): + return render_template("error.html", error_message="404 Not Found"), 404 + +@app.errorhandler(500) +def error_500(error): + return render_template("error.html", error_message="500 Internal Server Error"), 500 \ No newline at end of file diff --git a/tiny0/static/style.css b/tiny0/static/style.css index 9e17415..d5a3feb 100644 --- a/tiny0/static/style.css +++ b/tiny0/static/style.css @@ -11,8 +11,6 @@ body { .headers { position: absolute; - margin-left: auto; - margin-right: auto; left: 0; right: 0; top: 3vh; @@ -40,8 +38,6 @@ body { .container { position: absolute; - margin-left: auto; - margin-right: auto; left: 0; right: 0; background-color: #2c2c2c; @@ -86,7 +82,7 @@ body { border-color: #7b59a5; } -.error-message { +.url-error-message { color: #ffffff; text-align: center; font-size: 100%; @@ -94,6 +90,15 @@ body { margin: 3% 0 0 0; } +.error-message { + position: absolute; + left: 0; + right: 0; + color: #ffffff; + text-align: center; + margin: 40vh auto 0 auto; +} + .page-container { position: relative; min-height: 100vh; diff --git a/tiny0/templates/error.html b/tiny0/templates/error.html new file mode 100644 index 0000000..f91b805 --- /dev/null +++ b/tiny0/templates/error.html @@ -0,0 +1,13 @@ +{% extends "layout.html" %} + +{% block body %} + +
+ tiny0 +

Custom URL Shortener

+
+
+

{{ error_message }}

+
+ +{% endblock %} \ No newline at end of file diff --git a/tiny0/templates/index.html b/tiny0/templates/index.html index e45c483..241447f 100644 --- a/tiny0/templates/index.html +++ b/tiny0/templates/index.html @@ -24,7 +24,7 @@ {% if form.url.errors %} {% for error in form.url.errors %} -

{{ error }}

+

{{ error }}

{% endfor %} {% endif %}