Fix message format in validation exception handler (#755)

This commit is contained in:
Wu Clan
2025-08-05 18:11:02 +08:00
committed by GitHub
parent 8591d4e592
commit 1f8687155a

View File

@ -52,9 +52,9 @@ async def _validation_exception_handler(request: Request, exc: RequestValidation
if not ctx: if not ctx:
error['msg'] = custom_message error['msg'] = custom_message
else: else:
error['msg'] = custom_message.format(**ctx)
ctx_error = ctx.get('error') ctx_error = ctx.get('error')
if ctx_error: if ctx_error:
error['msg'] = custom_message.format(**ctx)
error['ctx']['error'] = ( error['ctx']['error'] = (
ctx_error.__str__().replace("'", '"') if isinstance(ctx_error, Exception) else None ctx_error.__str__().replace("'", '"') if isinstance(ctx_error, Exception) else None
) )