]> git.ipfire.org Git - pbs.git/commitdiff
errors: Refactor the error handler and drop any redundant templates
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 02:49:09 +0000 (02:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 19 Oct 2022 02:49:09 +0000 (02:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/errors/error-400.html [deleted file]
src/templates/errors/error-403.html [deleted file]
src/templates/errors/error-404.html [deleted file]
src/templates/errors/error.html
src/web/base.py

index 7f8f748bf4050278e76e1e6d9489bb3eb91c5621..5972d8a1ebcbc03e8deb48cf6c86678c970b6ae4 100644 (file)
@@ -218,10 +218,7 @@ dist_templates_distros_DATA = \
 templates_distrosdir = $(templatesdir)/distros
 
 dist_templates_errors_DATA = \
-       src/templates/errors/error.html \
-       src/templates/errors/error-400.html \
-       src/templates/errors/error-403.html \
-       src/templates/errors/error-404.html
+       src/templates/errors/error.html
 
 templates_errorsdir = $(templatesdir)/errors
 
diff --git a/src/templates/errors/error-400.html b/src/templates/errors/error-400.html
deleted file mode 100644 (file)
index f8bfaa2..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{% extends "error.html" %}
-
-{% block bigbox_headline %}
-       {{ _("400 - Bad request") }}
-{% end block %}
-
-{% block bigbox_subtitle %}
-       <small>{{ _("Invalid data has been passed to the application.") }}</small>
-{% end block %}
-
-{% block explanation %}
-       <p>
-               {{ _("The application refused to go on with the provided data that was sent in this request.") }}
-       </p>
-{% end block %}
-
-{% block message %}{% end block %}
diff --git a/src/templates/errors/error-403.html b/src/templates/errors/error-403.html
deleted file mode 100644 (file)
index a2bf15a..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{% extends "error.html" %}
-
-{% block bigbox_headline %}
-       {{ _("403 - Access forbidden") }}
-{% end block %}
-
-{% block bigbox_subtitle %}
-       <small>{{ _("You are not allowed to access this ressource.") }}</small>
-{% end block %}
-
-{% block explanation %}
-       <p>
-               {{ _("Access to the requested page has been denied because you do not have sufficient rights.") }}
-       </p>
-{% end block %}
-
-{% block message %}{% end block %}
diff --git a/src/templates/errors/error-404.html b/src/templates/errors/error-404.html
deleted file mode 100644 (file)
index c7a80fb..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-{% extends "error.html" %}
-
-{% block bigbox_headline %}
-       {{ _("404 - Not Found") }}
-{% end block %}
-
-{% block bigbox_subtitle %}
-       <small>{{ _("I could not find what you were searching for.") }}</small>
-{% end block %}
-
-{% block explanation %}
-       <p>
-               {{ _("You may have clicked an expired link or mistyped the address.") }}
-       </p>
-{% end block %}
-
-{% block message %}{% end block %}
index 726c47eb4e93f5a28fe500125885e77ec7029a0b..c1918a9d16d9b39a86b27e69cf651b9ec15a5f45 100644 (file)
@@ -8,18 +8,18 @@
                                        {{ _("Oops, something is not right...") }}
                                </p>
                                <p class="subtitle">
-                                       {{ status_code }} - {{ status_message }}
+                                       {{ code }} - {{ message }}
                                </p>
                        </div>
                </div>
        </section>
 
-       {% if current_user and current_user.is_admin() and tb %}
+       {% if traceback %}
                <section class="section">
                        <div class="container">
                                <h4 class="title is-4">{{ _("Exception (Traceback):") }}</h4>
 
-                               <pre>{{ "".join(tb) }}</pre>
+                               <pre>{{ traceback }}</pre>
                        </div>
                </section>
        {% end %}
index bde601a8b4811d2f797552679c5e6fac3eeb998b..c16d7a280c2e521e3bbaee3021c676b2fa512e68 100644 (file)
@@ -72,25 +72,21 @@ class BaseHandler(tornado.web.RequestHandler):
 
                return ns
 
-       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"
-
+       def write_error(self, code, exc_info=None, **kwargs):
                try:
-                       status_message = http.client.responses[status_code]
+                       message = http.client.responses[code]
                except KeyError:
-                       status_message = None
+                       message = None
+
+               _traceback = []
 
                # Collect more information about the exception if possible.
                if exc_info:
-                       tb = traceback.format_exception(*exc_info)
-               else:
-                       tb = None
+                       if self.current_user and self.current_user.is_admin():
+                               _traceback += traceback.format_exception(*exc_info)
 
-               self.render(error_document, status_code=status_code,
-                       status_message=status_message, exc_info=exc_info, tb=tb, **kwargs)
+               self.render("errors/error.html",
+                       code=code, message=message, traceback="".join(_traceback), **kwargs)
 
        # Typed Arguments