better override for json BadRequest error

This commit is contained in:
David Lord 2022-03-23 08:26:46 -07:00
parent 0a300d007d
commit 6578b493c8
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8

View file

@ -9,7 +9,6 @@ from .globals import current_app
from .helpers import _split_blueprint_path
if t.TYPE_CHECKING:
import typing_extensions as te
from werkzeug.routing import Rule
@ -124,11 +123,14 @@ class Request(RequestBase):
attach_enctype_error_multidict(self)
def on_json_loading_failed(self, e: Exception) -> "te.NoReturn":
if current_app and current_app.debug:
raise BadRequest(f"Failed to decode JSON object: {e}")
def on_json_loading_failed(self, e: ValueError) -> t.Any:
try:
return super().on_json_loading_failed(e)
except BadRequest as e:
if current_app and current_app.debug:
raise
raise BadRequest()
raise BadRequest() from e
class Response(ResponseBase):