From 95ab8908bf3dac10929bf5e8dd8a7a75717dfa75 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Fri, 17 Oct 2025 16:18:28 +0800 Subject: [PATCH 1/2] Fix ctx in validation exception handler --- backend/common/exception/exception_handler.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/common/exception/exception_handler.py b/backend/common/exception/exception_handler.py index 72288cf0..c87b3102 100644 --- a/backend/common/exception/exception_handler.py +++ b/backend/common/exception/exception_handler.py @@ -46,15 +46,15 @@ async def _validation_exception_handler(exc: RequestValidationError | Validation if i18n.current_language != 'en-US': custom_message = t(f'pydantic.{error["type"]}') if custom_message: - ctx = error.get('ctx') - if not ctx: + error_ctx = error.get('ctx') + if not error_ctx: error['msg'] = custom_message else: - ctx_error = ctx.get('error') - if ctx_error: - error['msg'] = custom_message.format(**ctx) + e = error_ctx.get('error') + if e: + error['msg'] = custom_message.format(**error_ctx) error['ctx']['error'] = ( - ctx_error.__str__().replace("'", '"') if isinstance(ctx_error, Exception) else None + e.__str__().replace("'", '"') if isinstance(e, Exception) else None ) errors.append(error) error = errors[0] From 8e3ab97c92804a2fea25818e880add68219cbeb1 Mon Sep 17 00:00:00 2001 From: Wu Clan Date: Fri, 17 Oct 2025 16:20:20 +0800 Subject: [PATCH 2/2] Fix lint --- backend/common/exception/exception_handler.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/common/exception/exception_handler.py b/backend/common/exception/exception_handler.py index c87b3102..575b26b5 100644 --- a/backend/common/exception/exception_handler.py +++ b/backend/common/exception/exception_handler.py @@ -53,9 +53,7 @@ async def _validation_exception_handler(exc: RequestValidationError | Validation e = error_ctx.get('error') if e: error['msg'] = custom_message.format(**error_ctx) - error['ctx']['error'] = ( - e.__str__().replace("'", '"') if isinstance(e, Exception) else None - ) + error['ctx']['error'] = e.__str__().replace("'", '"') if isinstance(e, Exception) else None errors.append(error) error = errors[0] if error.get('type') == 'json_invalid':