aboutsummaryrefslogtreecommitdiffstats
path: root/pysite
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-03-29 16:41:05 +0100
committerGravatar Gareth Coles <[email protected]>2018-03-29 16:41:05 +0100
commit24c7be0894d459c06862c3de6d3c038f517b44e5 (patch)
tree78711d55c543ebc5d7f0d04a602085711a325505 /pysite
parentfixes path to static files in subdomains (#46) (diff)
Fix error routing and more work on static files
Diffstat (limited to 'pysite')
-rw-r--r--pysite/base_route.py15
-rw-r--r--pysite/route_manager.py4
-rw-r--r--pysite/views/api/error_view.py4
3 files changed, 11 insertions, 12 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py
index 3bc04728..d63abaa6 100644
--- a/pysite/base_route.py
+++ b/pysite/base_route.py
@@ -4,6 +4,7 @@ from typing import Any
from flask import Blueprint, Response, jsonify, render_template
from flask.views import MethodView
+from werkzeug.exceptions import default_exceptions
from pysite.constants import DISCORD_OAUTH_REDIRECT, ErrorCodes
from pysite.mixins import OauthMixin
@@ -171,12 +172,12 @@ class ErrorView(BaseView):
if isinstance(cls.error_code, Iterable):
for code in cls.error_code:
- try:
- if cls.register_on_app:
- manager.app.errorhandler(code)(cls.as_view(cls.name))
- else:
- blueprint.errorhandler(code)(cls.as_view(cls.name))
- except KeyError: # This happens if we try to register a handler for a HTTP code that doesn't exist
- pass
+ if isinstance(code, int) and code not in default_exceptions:
+ continue # Otherwise we'll possibly get an exception thrown during blueprint registration
+
+ if cls.register_on_app:
+ manager.app.errorhandler(code)(cls.as_view(cls.name))
+ else:
+ blueprint.errorhandler(code)(cls.as_view(cls.name))
else:
raise RuntimeError("Error views must have an `error_code` that is either an `int` or an iterable") # pragma: no cover # noqa: E501
diff --git a/pysite/route_manager.py b/pysite/route_manager.py
index 949d4ed9..488c596f 100644
--- a/pysite/route_manager.py
+++ b/pysite/route_manager.py
@@ -66,12 +66,12 @@ class RouteManager:
for sub in self.subdomains:
sub_blueprint = Blueprint(sub, __name__, subdomain=sub)
self.log.debug(f"Loading Blueprint: {sub_blueprint.name}")
+ self.load_views(sub_blueprint, f"pysite/views/{sub}")
try:
self.app.register_blueprint(sub_blueprint)
except Exception:
logging.getLogger(__name__).exception(f"Failed to register blueprint for subdomain: {sub}")
- else:
- self.load_views(sub_blueprint, f"pysite/views/{sub}")
+ # exit(1)
# Load the websockets
self.ws_blueprint = Blueprint("ws", __name__)
diff --git a/pysite/views/api/error_view.py b/pysite/views/api/error_view.py
index 6d278604..30e133f9 100644
--- a/pysite/views/api/error_view.py
+++ b/pysite/views/api/error_view.py
@@ -1,7 +1,5 @@
# coding=utf-8
-from collections import Iterable
-
-from flask import jsonify, Blueprint
+from flask import jsonify
from werkzeug.exceptions import HTTPException
from pysite.base_route import ErrorView