From ef4cfc7597d7ce401b3a384bf22ef0b76f6b574e Mon Sep 17 00:00:00 2001 From: JoeBanks13 Date: Thu, 1 Mar 2018 19:45:09 +0000 Subject: Switch type from NotFound to HTTPException & add post support to 5XX and 4XX --- pysite/views/error_handlers/http_4xx.py | 13 +++++++++++-- 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 " + "open an issue on our GitHub."), 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): "file an issue on our GitHub" "."), 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 " + "file an issue on our GitHub" + "."), error.code -- cgit v1.2.3