From: Michael Tremer Date: Fri, 31 Aug 2018 16:32:20 +0000 (+0100) Subject: Add a simple error page X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37ed7c3c759b70d3c3981cacb92e871603b13608;p=ipfire.org.git Add a simple error page Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 65c85c50..ed421521 100644 --- a/Makefile.am +++ b/Makefile.am @@ -98,9 +98,7 @@ webdir = $(backenddir)/web templates_DATA = \ src/templates/base.html \ src/templates/donate.html \ - src/templates/error.html \ - src/templates/error-404.html \ - src/templates/error-500.html \ + src/templates/error.html src/templates/index.html templatesdir = $(datadir)/templates diff --git a/src/templates/error-404.html b/src/templates/error-404.html deleted file mode 100644 index 0535c634..00000000 --- a/src/templates/error-404.html +++ /dev/null @@ -1 +0,0 @@ -{% extends "error.html" %} diff --git a/src/templates/error-500.html b/src/templates/error-500.html deleted file mode 100644 index 5a48f4c0..00000000 --- a/src/templates/error-500.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "error.html" %} - -{% block explanation %} -
-
-

{{ _("Detailed information") }}

- -

- {{ _("While processing the request, there was an internal problem of the web server") }} -

-
-
-{% end block %} diff --git a/src/templates/error.html b/src/templates/error.html index 405a28a4..97025770 100644 --- a/src/templates/error.html +++ b/src/templates/error.html @@ -1,34 +1,16 @@ {% extends "base.html" %} -{% block title %}{{ _("Error") }} {{ code }}{% end block %} +{% block title %}{{ message or status_code }}{% end block %} {% block container %} -
-
-

{{ code }} - {{ message }}

- -
-
-

- {{ _("Unfortunately, an unexpected error has occurred during page load.") }} -

-

- If this is the first occurrence of the error, please wait a little bit - and try again. If the error occurs anyway the webmaster would be happy - to get a notification about this. -

+
+
+
+
{{ _("Error %s") % status_code }}
+

{{ _("oops, something went wrong") }}

- - {% block explanation %}{% end block %} - - {% if exception %} -
-
-
{{ exception }}
-
-
- {% end %} -
-
+ {% end block %} + +{% block footer %}{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 1f5fb492..2e1e9f05 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -111,6 +111,9 @@ class Application(tornado.web.Application): # Handle old pages that have moved elsewhere (r"/imprint", tornado.web.RedirectHandler, { "url" : "/legal" }), (r"/(de|en)/(.*)", LangCompatHandler), + + # Export arbitrary error pages + (r"/error/([45][0-9]{2})", ErrorHandler), ]) # blog.ipfire.org diff --git a/src/web/handlers_base.py b/src/web/handlers_base.py index 2dd0b66b..d75b0509 100644 --- a/src/web/handlers_base.py +++ b/src/web/handlers_base.py @@ -14,6 +14,15 @@ import tornado.web from .. import util class BaseHandler(tornado.web.RequestHandler): + def write_error(self, status_code, **kwargs): + # Translate code into message + try: + message = httplib.responses[status_code] + except KeyError: + message = None + + self.render("error.html", status_code=status_code, message=message, **kwargs) + @property def hostname(self): # Remove the development prefix @@ -214,7 +223,15 @@ class NotFoundHandler(BaseHandler): # Raises 404 as soon as it is called raise tornado.web.HTTPError(404) - def write_error(self, status_code, **kwargs): - assert status_code == 404 - self.render("error-404.html") +class ErrorHandler(BaseHandler): + """ + Raises any error we want + """ + def get(self, code): + try: + code = int(code) + except: + raise tornado.web.HTTPError(400) + + raise tornado.web.HTTPError(code)