handle cash-in errors
This commit is contained in:
parent
48dd23c11d
commit
86adfd0a63
7 changed files with 40 additions and 24 deletions
|
|
@ -5,6 +5,7 @@ const fs = require('fs')
|
|||
const pify = require('pify')
|
||||
|
||||
const BN = require('../../../bn')
|
||||
const E = require('../../../error')
|
||||
|
||||
const NAME = 'Bitcoind'
|
||||
|
||||
|
|
@ -28,12 +29,6 @@ function initRpc () {
|
|||
return new RpcClient(rpcConfig)
|
||||
}
|
||||
|
||||
function richError (msg, name) {
|
||||
const err = new Error(msg)
|
||||
err.name = name
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
* initialize RpcClient
|
||||
*/
|
||||
|
|
@ -68,7 +63,7 @@ function balance (account, cryptoCode) {
|
|||
if (err) return reject(err)
|
||||
|
||||
if (result.error) {
|
||||
return reject(richError(result.error, 'bitcoindError'))
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
resolve(BN(result.result).shift(SATOSHI_SHIFT).round())
|
||||
|
|
@ -85,15 +80,8 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
|||
checkCryptoCode(cryptoCode)
|
||||
rpc.sendFrom(pluginConfig.account, address, bitcoins, confirmations, (err, result) => {
|
||||
if (err) {
|
||||
if (err.code === -6) {
|
||||
return reject(richError('Insufficient funds', 'InsufficientFunds'))
|
||||
}
|
||||
|
||||
if (err instanceof Error) {
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
return reject(richError(err.message, 'bitcoindError'))
|
||||
if (err.code === -6) return reject(new E.InsufficientFundsError())
|
||||
return reject(err)
|
||||
}
|
||||
|
||||
resolve(result.result)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue