diff --git a/lib/cash-in-tx.js b/lib/cash-in-tx.js index db538acd..37ce2171 100644 --- a/lib/cash-in-tx.js +++ b/lib/cash-in-tx.js @@ -76,6 +76,7 @@ function ensureRatchet (oldField, newField, fieldKey) { const free = ['sendPending', 'error', 'errorCode', 'customerId'] if (_.isNil(oldField)) return true + if (_.includes(fieldKey, monotonic)) return isMonotonic(oldField, newField, fieldKey) if (_.includes(fieldKey, free)) { @@ -106,7 +107,7 @@ function diff (oldTx, newTx) { logger.warn('Value from lamassu-machine would violate ratchet [%s]', fieldKey) logger.warn('Old tx: %j', oldTx) logger.warn('New tx: %j', newTx) - throw new Error('Value from lamassu-machine would violate ratchet') + throw new E.RatchetError('Value from lamassu-machine would violate ratchet') } updatedTx[fieldKey] = newField diff --git a/lib/cash-out-tx.js b/lib/cash-out-tx.js index 9b2ecac9..30f823f3 100644 --- a/lib/cash-out-tx.js +++ b/lib/cash-out-tx.js @@ -245,7 +245,6 @@ function preProcess (oldTx, newTx, pi) { const hasDispenseOccurred = !dispenseOccurred(oldTx.bills) && dispenseOccurred(newTx.bills) if (hasError || hasDispenseOccurred) { - console.log('DEBUG100') return logDispense(updatedTx) .then(updateCassettes(updatedTx)) } diff --git a/lib/error.js b/lib/error.js index 41f8f56e..e0c1ce2e 100644 --- a/lib/error.js +++ b/lib/error.js @@ -23,3 +23,4 @@ register('BadNumberError') register('NoDataError') register('InsufficientFundsError') register('StaleTxError') +register('RatchetError') diff --git a/lib/routes.js b/lib/routes.js index dcb6ee1b..86882de9 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -123,7 +123,9 @@ function postTx (req, res, next) { return res.json(tx) }) .catch(err => { - if (err instanceof E.StaleTxError) return res.status(404).json({}) + if (err instanceof E.StaleTxError) return res.status(409).json({}) + if (err instanceof E.RatchetError) return res.status(409).json({}) + throw err }) .catch(next)