From: Michael Tremer Date: Wed, 25 Oct 2017 17:49:38 +0000 (+0100) Subject: Fix rendering error pages X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=703e79ed31377ebee4ae44a7398c119a1257523a;p=pbs.git Fix rendering error pages Signed-off-by: Michael Tremer --- diff --git a/src/templates/errors/error.html b/src/templates/errors/error.html index 7d7232b4..892acea0 100644 --- a/src/templates/errors/error.html +++ b/src/templates/errors/error.html @@ -29,15 +29,15 @@ {{ _("Error code") }} - {{ code }} - {{ message }} + {{ status_code }} - {{ status_message }} - {% if current_user and current_user.is_admin() and exception %} + {% if current_user and current_user.is_admin() and tb %} {{ _("Exception (traceback):") }}

-
{{ exception }}
+
{{ "\n".join(tb) }}
{% end %} diff --git a/src/web/base.py b/src/web/base.py index 23e05d83..6f77a7ec 100644 --- a/src/web/base.py +++ b/src/web/base.py @@ -91,22 +91,25 @@ class BaseHandler(tornado.web.RequestHandler): return ns - def get_error_html(self, status_code, exception=None, **kwargs): - error_document = "errors/error.html" - - kwargs.update({ - "code" : status_code, - "message" : httplib.responses[status_code], - }) - + def write_error(self, status_code, exc_info=None, **kwargs): if status_code in (400, 403, 404): error_document = "errors/error-%s.html" % status_code + else: + error_document = "errors/error.html" + + try: + status_message = httplib.responses[status_code] + except KeyError: + status_message = None # Collect more information about the exception if possible. - if exception: - exception = traceback.format_exc() + if exc_info: + tb = traceback.format_exception(*exc_info) + else: + tb = None - return self.render_string(error_document, exception=exception, **kwargs) + self.render(error_document, status_code=status_code, + status_message=status_message, exc_info=exc_info, tb=tb, **kwargs) @property def pakfire(self):