From b9c3a3fcea28af79a8d9dab510df10151f3e17be Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 21 Jul 2019 18:19:07 +0200 Subject: [PATCH] Fix #652 --- cps/static/css/style.css | 1 + cps/templates/http_error.html | 28 ++++++++++++++++++++++++++-- cps/web.py | 20 ++++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/cps/static/css/style.css b/cps/static/css/style.css index 1880207a..aaa7503e 100644 --- a/cps/static/css/style.css +++ b/cps/static/css/style.css @@ -141,6 +141,7 @@ input.pill:not(:checked) + label .glyphicon { .filterheader { margin-bottom: 20px; } +.errorlink {margin-top: 20px;} .modal-body .comments { max-height:300px; overflow-y: auto; diff --git a/cps/templates/http_error.html b/cps/templates/http_error.html index 36471fce..1f09a79d 100644 --- a/cps/templates/http_error.html +++ b/cps/templates/http_error.html @@ -17,10 +17,34 @@ {% endif %} -
-

{{ error_code }}

+
+
+
+

{{ error_code }}

{{ error_name }}

+
+
+
+
+ {% for element in error_stack %} +
{{ element }}
+ {% endfor %} +
+
+ {% if issue %} +
+ +
+ {% endif %} + + + +
diff --git a/cps/web.py b/cps/web.py index bab52edb..66428202 100644 --- a/cps/web.py +++ b/cps/web.py @@ -27,6 +27,8 @@ import base64 import datetime import json import mimetypes +import traceback +import sys from babel import Locale as LC from babel.dates import format_date @@ -83,16 +85,30 @@ except ImportError: # custom error page def error_http(error): return render_template('http_error.html', - error_code=error.code, + error_code="Error {0}".format(error.code), error_name=error.name, + issue=False, instance=config.config_calibre_web_title ), error.code + +def internal_error(error): + __, __, tb = sys.exc_info() + return render_template('http_error.html', + error_code="Internal Server Error", + error_name=str(error), + issue=True, + error_stack=traceback.format_tb(tb), + instance=config.config_calibre_web_title + ), 500 + + # http error handling for ex in default_exceptions: - # new routine for all client errors, server errors stay if ex < 500: app.register_error_handler(ex, error_http) + elif ex == 500: + app.register_error_handler(ex, internal_error) web = Blueprint('web', __name__)