Skip to content

Commit

Permalink
✨ Preserve json.JSONDecodeError information when handling invalid J…
Browse files Browse the repository at this point in the history
…SON 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>
  • Loading branch information
3 people committed Aug 25, 2022
1 parent afaa039 commit 9359a8d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fastapi/routing.py
Expand Up @@ -209,7 +209,9 @@ async def app(request: Request) -> Response:
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"
Expand Down

0 comments on commit 9359a8d

Please sign in to comment.