mirror of https://github.com/tiangolo/fastapi.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 <tiangolo@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
afaa0391a5
commit
9359a8d65f
|
|
@ -209,7 +209,9 @@ def get_request_handler(
|
||||||
else:
|
else:
|
||||||
body = body_bytes
|
body = body_bytes
|
||||||
except json.JSONDecodeError as e:
|
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:
|
except Exception as e:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=400, detail="There was an error parsing the body"
|
status_code=400, detail="There was an error parsing the body"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue