aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar JoeBanks13 <[email protected]>2018-04-05 20:00:14 +0100
committerGravatar JoeBanks13 <[email protected]>2018-04-05 20:00:14 +0100
commit068656c353fb29e370c07964ddd20f899ec7becd (patch)
treee100bd83734b0f612b5dc274b4aa20f694f6ea84
parentFlake8 (diff)
5XX error view non-werkzeug exception support
-rw-r--r--pysite/views/error_handlers/http_5xx.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/pysite/views/error_handlers/http_5xx.py b/pysite/views/error_handlers/http_5xx.py
index 4f91aeb1..14c016c5 100644
--- a/pysite/views/error_handlers/http_5xx.py
+++ b/pysite/views/error_handlers/http_5xx.py
@@ -1,6 +1,6 @@
# coding=utf-8
from flask import request
-from werkzeug.exceptions import HTTPException
+from werkzeug.exceptions import HTTPException, InternalServerError
from pysite.base_route import ErrorView
from pysite.constants import ERROR_DESCRIPTIONS
@@ -23,6 +23,14 @@ class Error500View(ErrorView):
setattr(self, method, self.error)
def error(self, error: HTTPException):
+
+ # We were sometimes recieving errors from RethinkDB, which were not originating from Werkzeug.
+ # To fix this, this section checks whether they have a code (which werkzeug adds) and if not
+ # change the error to a Werkzeug InternalServerError.
+
+ if not hasattr(error, "code"):
+ error = InternalServerError()
+
error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.")
return self.render(