✨ 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 <tiangolo@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2022-08-25 11:55:53 +02:00
1 parent afaa0391a5
commit 9359a8d65f
1 file changed
+3 -1
+3 -1
View File
@@ -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"