Skip to content

Commit 27383e4

Browse files
authored
Fix ctx in validation exception handler (#861)
* Fix ctx in validation exception handler * Fix lint
1 parent bf16f89 commit 27383e4

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

backend/common/exception/exception_handler.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,14 @@ async def _validation_exception_handler(exc: RequestValidationError | Validation
4646
if i18n.current_language != 'en-US':
4747
custom_message = t(f'pydantic.{error["type"]}')
4848
if custom_message:
49-
ctx = error.get('ctx')
50-
if not ctx:
49+
error_ctx = error.get('ctx')
50+
if not error_ctx:
5151
error['msg'] = custom_message
5252
else:
53-
ctx_error = ctx.get('error')
54-
if ctx_error:
55-
error['msg'] = custom_message.format(**ctx)
56-
error['ctx']['error'] = (
57-
ctx_error.__str__().replace("'", '"') if isinstance(ctx_error, Exception) else None
58-
)
53+
e = error_ctx.get('error')
54+
if e:
55+
error['msg'] = custom_message.format(**error_ctx)
56+
error['ctx']['error'] = e.__str__().replace("'", '"') if isinstance(e, Exception) else None
5957
errors.append(error)
6058
error = errors[0]
6159
if error.get('type') == 'json_invalid':

0 commit comments

Comments
 (0)