From 9e116d4b202c84cb5fdfdfa495d86bc98f1072d3 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 1 Aug 2019 16:20:18 -0400 Subject: [PATCH] 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.
+ +
+ +
+ +
+ +
+ + + + +