aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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