Catch a 500 and make it a 400

While we are at it, convert __all__ to non_field_errors automatically
This commit is contained in:
Oliver Walters 2022-05-17 00:35:24 +10:00
parent ae50546ca6
commit 6512c0061e
2 changed files with 10 additions and 1 deletions

View File

@ -77,4 +77,9 @@ def exception_handler(exc, context):
# For an error response, include status code information # For an error response, include status code information
response.data['status_code'] = response.status_code response.data['status_code'] = response.status_code
# Convert errors returned under the label '__all__' to 'non_field_errors'
if '__all__' in response.data:
response.data['non_field_errors'] = response.data['all']
del response.data['__all__']
return response return response

View File

@ -1287,13 +1287,17 @@ class SalesOrderShipmentAllocationSerializer(serializers.Serializer):
with transaction.atomic(): with transaction.atomic():
for entry in items: for entry in items:
# Create a new SalesOrderAllocation # Create a new SalesOrderAllocation
order.models.SalesOrderAllocation.objects.create( allocation = order.models.SalesOrderAllocation(
line=entry.get('line_item'), line=entry.get('line_item'),
item=entry.get('stock_item'), item=entry.get('stock_item'),
quantity=entry.get('quantity'), quantity=entry.get('quantity'),
shipment=shipment, shipment=shipment,
) )
allocation.full_clean()
allocation.save()
class SalesOrderExtraLineSerializer(AbstractExtraLineSerializer, InvenTreeModelSerializer): class SalesOrderExtraLineSerializer(AbstractExtraLineSerializer, InvenTreeModelSerializer):