improve handling of ratchet error
This commit is contained in:
parent
fc17d2cdf8
commit
d7a5734818
4 changed files with 6 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,3 +23,4 @@ register('BadNumberError')
|
|||
register('NoDataError')
|
||||
register('InsufficientFundsError')
|
||||
register('StaleTxError')
|
||||
register('RatchetError')
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue