diff options
author | 2018-03-01 19:45:09 +0000 | |
---|---|---|
committer | 2018-03-01 19:45:09 +0000 | |
commit | ef4cfc7597d7ce401b3a384bf22ef0b76f6b574e (patch) | |
tree | f64794b5c8b70e53747b9ea1c666eb8482dcd2b6 | |
parent | Gdude got nit picky and made me change the Mac OS terminal to say it's on Mac (diff) |
Switch type from NotFound to HTTPException & add post support to 5XX and 4XX
-rw-r--r-- | pysite/views/error_handlers/http_4xx.py | 13 | ||||
-rw-r--r-- | pysite/views/error_handlers/http_5xx.py | 15 |
2 files changed, 26 insertions, 2 deletions
diff --git a/pysite/views/error_handlers/http_4xx.py b/pysite/views/error_handlers/http_4xx.py index 5874b862..5717feae 100644 --- a/pysite/views/error_handlers/http_4xx.py +++ b/pysite/views/error_handlers/http_4xx.py @@ -1,6 +1,6 @@ # coding=utf-8 from flask import render_template, request -from werkzeug.exceptions import NotFound +from werkzeug.exceptions import HTTPException from pysite.base_route import ErrorView from pysite.constants import ERROR_DESCRIPTIONS @@ -10,7 +10,16 @@ class Error400View(ErrorView): name = "error_4xx" error_code = range(400, 430) - def get(self, error: NotFound): + def get(self, error: HTTPException): + error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") + + return render_template("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 + + def post(self, error: HTTPException): error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, diff --git a/pysite/views/error_handlers/http_5xx.py b/pysite/views/error_handlers/http_5xx.py index 410be265..6bbc8275 100644 --- a/pysite/views/error_handlers/http_5xx.py +++ b/pysite/views/error_handlers/http_5xx.py @@ -23,3 +23,18 @@ 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 render_template("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 |