fix: Error response optimization (#3789)
This commit is contained in:
parent
aee0b251dc
commit
2de1d817d7
@ -10,6 +10,7 @@ import logging
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from rest_framework.exceptions import ValidationError, ErrorDetail, APIException
|
from rest_framework.exceptions import ValidationError, ErrorDetail, APIException
|
||||||
|
from rest_framework.utils.serializer_helpers import ReturnDict
|
||||||
from rest_framework.views import exception_handler
|
from rest_framework.views import exception_handler
|
||||||
|
|
||||||
from common import result
|
from common import result
|
||||||
@ -71,7 +72,10 @@ def find_err_detail(exc_detail):
|
|||||||
if isinstance(_value, ErrorDetail):
|
if isinstance(_value, ErrorDetail):
|
||||||
return f"{_label}:{find_err_detail(_value)}"
|
return f"{_label}:{find_err_detail(_value)}"
|
||||||
if isinstance(_value, dict) and len(_value.keys()) > 0:
|
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):
|
if isinstance(exc_detail, list):
|
||||||
for v in exc_detail:
|
for v in exc_detail:
|
||||||
r = find_err_detail(v)
|
r = find_err_detail(v)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user