From eb42655c46f8a598f2e0ead624ba5a65a8a66e90 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 29 Jan 2021 11:03:33 -0800 Subject: [PATCH] simplify BadRequestKeyError.show_exception --- src/flask/app.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/flask/app.py b/src/flask/app.py index 4cbad04b..d7d96cdb 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -1386,17 +1386,10 @@ class Flask(Scaffold): .. versionadded:: 0.7 """ - if isinstance(e, BadRequestKeyError): - if self.debug or self.config["TRAP_BAD_REQUEST_ERRORS"]: - e.show_exception = True - - # Werkzeug < 0.15 doesn't add the KeyError to the 400 - # message, add it in manually. - # TODO: clean up once Werkzeug >= 0.15.5 is required - if e.args[0] not in e.get_description(): - e.description = f"KeyError: {e.args[0]!r}" - elif not hasattr(BadRequestKeyError, "show_exception"): - e.args = () + if isinstance(e, BadRequestKeyError) and ( + self.debug or self.config["TRAP_BAD_REQUEST_ERRORS"] + ): + e.show_exception = True if isinstance(e, HTTPException) and not self.trap_http_exception(e): return self.handle_http_exception(e)