From 9e116d4b202c84cb5fdfdfa495d86bc98f1072d3 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 1 Aug 2019 16:20:18 -0400 Subject: [PATCH 1/3] add error page --- CherryPyApp.py | 7 +++ errors.py | 15 ++++++ templates/error.html | 123 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100755 errors.py create mode 100644 templates/error.html diff --git a/CherryPyApp.py b/CherryPyApp.py index 778237e..6ab09b2 100644 --- a/CherryPyApp.py +++ b/CherryPyApp.py @@ -42,6 +42,7 @@ import QRCodePage import diagnostics import Sitemap import Formatters +from errors import ErrorPage import Timer @@ -51,6 +52,10 @@ install_dir = os.path.dirname(os.path.abspath(__file__)) CHERRYPY_CONFIG = os.path.join(install_dir, 'CherryPy.conf') LOCAL_CONFIG = [os.path.expanduser('~/.autocat3'), '/etc/autocat3.conf'] +def error_page_404(status, message, traceback, version): + return ErrorPage(status, message).index() + + class MyRoutesDispatcher(cherrypy.dispatch.RoutesDispatcher): """ Dispatcher that tells us the matched route. @@ -157,6 +162,8 @@ def main(): cherrypy.config['all_hosts'] = ( cherrypy.config['host'], cherrypy.config['host_mobile'], cherrypy.config['file_host']) + + cherrypy.config.update({'error_page.404': error_page_404}) if hasattr(cherrypy.engine, 'signal_handler'): cherrypy.engine.signal_handler.subscribe() diff --git a/errors.py b/errors.py new file mode 100755 index 0000000..af04738 --- /dev/null +++ b/errors.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- mode: python; indent-tabs-mode: nil; -*- coding: utf-8 -*- + +from BaseSearcher import OpenSearch +from Page import Page +import Formatters + +class ErrorPage(Page): + + def __init__(self, status=500, message='undefined error'): + self.message = message + self.status = status + + def index(self): + return Formatters.formatters['html'].render('error', self) \ No newline at end of file diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..52604e1 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + ${os.message} + + +
+ +
+
+

${os.message}

+
+ +
+ + +
+
+ + +
+ + + +
+ + + + + + + + + + + + + + +
+ + + + + +
Project Gutenberg offers thousands of free ebooks to download.
+ +
+ +
+ +
+ +
+ + + + + From 6943b60c0ab7f63fcfb12de56944ad732306d2d6 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 1 Aug 2019 19:40:23 -0400 Subject: [PATCH 2/3] don't save sessions for 404's --- CherryPyApp.py | 6 +++++- errors.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CherryPyApp.py b/CherryPyApp.py index 6ab09b2..192bb8c 100644 --- a/CherryPyApp.py +++ b/CherryPyApp.py @@ -53,7 +53,11 @@ CHERRYPY_CONFIG = os.path.join(install_dir, 'CherryPy.conf') LOCAL_CONFIG = [os.path.expanduser('~/.autocat3'), '/etc/autocat3.conf'] def error_page_404(status, message, traceback, version): - return ErrorPage(status, message).index() + resp = ErrorPage(status, message).index() + + # signal that we needn't save the session + cherrypy.session.loaded = False + return resp class MyRoutesDispatcher(cherrypy.dispatch.RoutesDispatcher): diff --git a/errors.py b/errors.py index af04738..fed07d4 100755 --- a/errors.py +++ b/errors.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- mode: python; indent-tabs-mode: nil; -*- coding: utf-8 -*- - +import cherrypy from BaseSearcher import OpenSearch from Page import Page import Formatters From 75c1f6262fa34e7514cfc4271da26f7923dc240d Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 2 Aug 2019 10:45:50 -0400 Subject: [PATCH 3/3] javascript needed for help popup --- templates/error.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/error.html b/templates/error.html index 52604e1..ea21006 100644 --- a/templates/error.html +++ b/templates/error.html @@ -11,9 +11,22 @@ - + +