aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar JoeBanks13 <[email protected]>2018-03-21 18:25:15 +0000
committerGravatar JoeBanks13 <[email protected]>2018-03-21 18:25:15 +0000
commitb9d81017c42e7759e694f0b8a36345c1694211b3 (patch)
treef9b601b60cb4a33c8d7be3daa3498e921ef8cb1e
parentUpdate PR documentation to mention team number in title (diff)
Copy code from API error view over to normal error views because that's the way it should be.
Diffstat (limited to '')
-rw-r--r--pysite/views/error_handlers/http_4xx.py20
-rw-r--r--pysite/views/error_handlers/http_5xx.py25
2 files changed, 24 insertions, 21 deletions
diff --git a/pysite/views/error_handlers/http_4xx.py b/pysite/views/error_handlers/http_4xx.py
index 74d43d6c..0f0f8a58 100644
--- a/pysite/views/error_handlers/http_4xx.py
+++ b/pysite/views/error_handlers/http_4xx.py
@@ -10,17 +10,19 @@ class Error400View(ErrorView):
name = "error_4xx"
error_code = range(400, 430)
- def get(self, error: HTTPException):
- error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.")
+ def __init__(self):
- return self.render(
- "errors/error.html", code=error.code, req=request, error_title=error_desc,
- error_message=error_desc +
- " If you believe we have made a mistake, please "
- "<a href='https://github.com/discord-python/site/issues'>open an issue on our GitHub</a>."
- ), error.code
+ # Direct errors for all methods at self.return_error
+ methods = [
+ 'get', 'post', 'put',
+ 'delete', 'patch', 'connect',
+ 'options', 'trace'
+ ]
+
+ for method in methods:
+ setattr(self, method, self.error)
- def post(self, error: HTTPException):
+ def error(self, error: HTTPException):
error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.")
return self.render(
diff --git a/pysite/views/error_handlers/http_5xx.py b/pysite/views/error_handlers/http_5xx.py
index 60d3b1bb..f5bf1bfa 100644
--- a/pysite/views/error_handlers/http_5xx.py
+++ b/pysite/views/error_handlers/http_5xx.py
@@ -10,7 +10,19 @@ class Error500View(ErrorView):
name = "error_5xx"
error_code = range(500, 600)
- def get(self, error: HTTPException):
+ def __init__(self):
+
+ # Direct errors for all methods at self.return_error
+ methods = [
+ 'get', 'post', 'put',
+ 'delete', 'patch', 'connect',
+ 'options', 'trace'
+ ]
+
+ for method in methods:
+ setattr(self, method, self.error)
+
+ def error(self, error: HTTPException):
error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.")
return self.render(
@@ -20,14 +32,3 @@ class Error500View(ErrorView):
"<a href='https://github.com/discord-python/site/issues'>file an issue on our"
" GitHub</a>."
), error.code
-
- def post(self, error: HTTPException):
- error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.")
-
- return self.render(
- "errors/error.html", code=error.code, req=request, error_title=error_desc,
- error_message="An error occurred while processing this request, please try "
- "again later. If you believe we have made a mistake, please "
- "<a href='https://github.com/discord-python/site/issues'>file an issue on our"
- " GitHub</a>."
- ), error.code