mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-09 17:38:49 -04:00
✨ 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:
committed by
GitHub
parent
afaa0391a5
commit
9359a8d65f
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user