]> git.ipfire.org Git - pbs.git/commitdiff
Fix rendering error pages
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Oct 2017 17:49:38 +0000 (18:49 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Oct 2017 17:49:38 +0000 (18:49 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/templates/errors/error.html
src/web/base.py

index 7d7232b4f2d477b2f0d8247a19835d8b9cf0aed9..892acea0cedb1bd1e620a04a807038db05ce2ea9 100644 (file)
                                        <tbody>
                                                <tr>
                                                        <td>{{ _("Error code") }}</td>
-                                                       <td>{{ code }} - {{ message }}</td>
+                                                       <td>{{ status_code }} - {{ status_message }}</td>
                                                </tr>
 
-                                               {% if current_user and current_user.is_admin() and exception %}
+                                               {% if current_user and current_user.is_admin() and tb %}
                                                        <tr>
                                                                <td colspan="2">
                                                                        {{ _("Exception (traceback):") }}
                                                                        <br><br>
-                                                                       <pre>{{ exception }}</pre>
+                                                                       <pre>{{ "\n".join(tb) }}</pre>
                                                                </td>
                                                        </tr>
                                                {% end %}
index 23e05d834c39e75ce3016229732c4fe13ccaa101..6f77a7ec85bf31b1cc452f46ad3682b0550daece 100644 (file)
@@ -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):