Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/common/exception/handle_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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
Expand Down Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No significant irregularities, potential issues, or optimization suggestions were identified in the provided code snippet. The approach to handling error details within exception_handler ensures that both individual ErrorDetail, nested dictionaries, and lists of errors are properly processed and converted into a human-readable format using ReturnDict.

Expand Down
Loading