From: Sidharth Ajithkumar Date: Thu, 25 Aug 2022 09:55:53 +0000 (+0530) Subject: ✨ Preserve `json.JSONDecodeError` information when handling invalid JSON in request... X-Git-Tag: 0.81.0~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9359a8d65fdff4460d01d652ccafd31507c6c426;p=thirdparty%2Ffastapi%2Ffastapi.git ✨ Preserve `json.JSONDecodeError` information when handling invalid JSON in request body, to support custom exception handlers that use its information (#4057) Co-authored-by: Sebastián Ramírez Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- diff --git a/fastapi/routing.py b/fastapi/routing.py index 80bd53279a..8f4d0fa7ef 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -209,7 +209,9 @@ def get_request_handler( else: body = body_bytes except json.JSONDecodeError as e: - raise RequestValidationError([ErrorWrapper(e, ("body", e.pos))], body=e.doc) + raise RequestValidationError( + [ErrorWrapper(e, ("body", e.pos))], body=e.doc + ) from e except Exception as e: raise HTTPException( status_code=400, detail="There was an error parsing the body"