From: Michael Tremer Date: Wed, 25 Oct 2017 17:37:05 +0000 (+0100) Subject: web: Move 404 handler into an own file X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cf8c7eac8295d65d1b57ea6f9fa9937cb83c7c4;p=pbs.git web: Move 404 handler into an own file Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 01bda2ee..f01eaace 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,6 +124,7 @@ hubdir = $(buildservicedir)/hub web_PYTHON = \ src/web/__init__.py \ src/web/base.py \ + src/web/errors.py \ src/web/handlers.py \ src/web/handlers_api.py \ src/web/handlers_auth.py \ diff --git a/src/web/__init__.py b/src/web/__init__.py index 9b3b9b3f..01425ba9 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -16,6 +16,7 @@ from ..decorators import * from .handlers import * from . import handlers_api +from . import errors from . import mirrors from . import ui_modules @@ -233,7 +234,7 @@ class Application(tornado.web.Application): # API handlers (r"/api/packages/autocomplete", handlers_api.ApiPackagesAutocomplete), - ], **settings) + ], default_handler_class=errors.Error404Handler, **settings) logging.info("Successfully initialied application") diff --git a/src/web/errors.py b/src/web/errors.py new file mode 100644 index 00000000..0a47fb10 --- /dev/null +++ b/src/web/errors.py @@ -0,0 +1,9 @@ +#!/usr/bin/python + +import tornado.web + +from . import base + +class Error404Handler(base.BaseHandler): + def prepare(self): + raise tornado.web.HTTPError(404) diff --git a/src/web/handlers.py b/src/web/handlers.py index 50b298a9..dc8803bc 100644 --- a/src/web/handlers.py +++ b/src/web/handlers.py @@ -33,11 +33,6 @@ class IndexHandler(base.BaseHandler): self.render("index.html", jobs=jobs, updates=updates) -class Error404Handler(base.BaseHandler): - def get(self): - raise tornado.web.HTTPError(404) - - class UploadsHandler(base.BaseHandler): @tornado.web.authenticated def get(self):