mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Error handling fix (#6741)
* Handle case where error message is *not* a dict * Encode as list
This commit is contained in:
parent
ae6803095c
commit
ca8f0cee9f
@ -352,7 +352,12 @@ class InvenTreeModelSerializer(serializers.ModelSerializer):
|
|||||||
try:
|
try:
|
||||||
instance.full_clean()
|
instance.full_clean()
|
||||||
except (ValidationError, DjangoValidationError) as exc:
|
except (ValidationError, DjangoValidationError) as exc:
|
||||||
data = exc.message_dict
|
if hasattr(exc, 'message_dict'):
|
||||||
|
data = exc.message_dict
|
||||||
|
elif hasattr(exc, 'message'):
|
||||||
|
data = {'non_field_errors': [str(exc.message)]}
|
||||||
|
else:
|
||||||
|
data = {'non_field_errors': [str(exc)]}
|
||||||
|
|
||||||
# Change '__all__' key (django style) to 'non_field_errors' (DRF style)
|
# Change '__all__' key (django style) to 'non_field_errors' (DRF style)
|
||||||
if '__all__' in data:
|
if '__all__' in data:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user