handle cash-in errors

This commit is contained in:
Josh Harvey 2017-04-23 13:44:36 +03:00
parent 48dd23c11d
commit 86adfd0a63
7 changed files with 40 additions and 24 deletions

View file

@ -15,6 +15,7 @@ const plugins = require('./plugins')
const helpers = require('./route-helpers')
const poller = require('./poller')
const Tx = require('./tx')
const E = require('./error')
const argv = require('minimist')(process.argv.slice(2))
@ -102,7 +103,17 @@ function postTx (req, res, next) {
const pi = plugins(req.settings, req.deviceId)
return Tx.post(_.set('deviceId', req.deviceId, req.body), pi)
.then(tx => res.json(tx))
.then(tx => {
if (tx.errorCode) {
console.log('DEBUG100: %s, %s', tx.errorCode, E.InsufficientFundsError.name)
if (tx.errorCode === E.InsufficientFundsError.code) {
throw httpError(tx.error, 570)
}
throw httpError(tx.error, 500)
}
return res.json(tx)
})
.catch(next)
}