To send a custom message for Pydantic errors, we require the error type
. Pydantic's error details are lost while building the error message in SignatureModel._build_error_message
. If we add the exc
dict to this message, it will be propagated to exception handlers
"SignatureModel"
@classmethod
def _build_error_message(
cls,
keys: Sequence[str],
exc_msg: str,
connection: ASGIConnection,
exc: Optional[Dict[str, Any]] = None
) -> ErrorMessage:
...
if exc:
message["exc"] = exc
...
Then in an exception handler, Pydantic's error dict can be accessed by:
validation_exception["extra"][0]["exc"]
No response
Is there a better way to propagate Pydantic's error object to ValidationException
received by the handlers?
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too