Try to return JSON error when receiving API call fails

although in my testing, the error still got raised somehow in the
tweens or something?  client then sees it as a 500 response and gets
no JSON
This commit is contained in:
Lance Edgar 2024-04-11 14:14:27 -05:00
parent a1b05540be
commit de8751b86c

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2023 Lance Edgar
# Copyright © 2010-2024 Lance Edgar
#
# This file is part of Rattail.
#
@ -27,6 +27,7 @@ Tailbone Web API - Receiving Batches
import logging
import humanize
import sqlalchemy as sa
from rattail.db import model
from rattail.util import pretty_quantity
@ -440,9 +441,17 @@ class ReceivingBatchRowViews(APIBatchRowView):
# handler takes care of the row receiving logic for us
kwargs = dict(form.validated)
del kwargs['row']
try:
self.batch_handler.receive_row(row, **kwargs)
self.Session.flush()
except Exception as error:
log.warning("receive() failed", exc_info=True)
if isinstance(error, sa.exc.DataError) and hasattr(error, 'orig'):
error = str(error.orig)
else:
error = str(error)
return {'error': error}
return self._get(obj=row)
@classmethod