From 2de1d817d70f25f6774b4d68902d9e873410f8c1 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Thu, 31 Jul 2025 16:17:23 +0800 Subject: [PATCH] fix: Error response optimization (#3789) --- apps/common/exception/handle_exception.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/common/exception/handle_exception.py b/apps/common/exception/handle_exception.py index 6f11aa5d4..ee128f865 100644 --- a/apps/common/exception/handle_exception.py +++ b/apps/common/exception/handle_exception.py @@ -10,6 +10,7 @@ import logging import traceback from rest_framework.exceptions import ValidationError, ErrorDetail, APIException +from rest_framework.utils.serializer_helpers import ReturnDict from rest_framework.views import exception_handler from common import result @@ -71,7 +72,10 @@ def find_err_detail(exc_detail): if isinstance(_value, ErrorDetail): return f"{_label}:{find_err_detail(_value)}" if isinstance(_value, dict) and len(_value.keys()) > 0: - return find_err_detail(_value) + try: + return find_err_detail(ReturnDict(_value, serializer=exc_detail.serializer.fields[key])) + except Exception as e: + return _value if isinstance(exc_detail, list): for v in exc_detail: r = find_err_detail(v)