aboutsummaryrefslogtreecommitdiffstats
path: root/pysite/base_route.py
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/base_route.py
parentfixes path to static files in subdomains (#46) (diff)
Fix error routing and more work on static files
Diffstat (limited to 'pysite/base_route.py')
-rw-r--r--pysite/base_route.py15
1 files changed, 8 insertions, 7 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