From a18e5496949ebc47c5e653a6eb9cc486563da8e1 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 19 Jun 2021 10:41:49 -0700 Subject: [PATCH] fix(raw-transactions): Adding better error handling for rate-limits --- src/raw-transactions.js | 12 ++++++------ test/integration/rawtransaction.js | 11 ++++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/raw-transactions.js b/src/raw-transactions.js index 675f0af..6968ed9 100644 --- a/src/raw-transactions.js +++ b/src/raw-transactions.js @@ -120,8 +120,8 @@ class RawTransactions { throw new Error('Input must be a string or array of strings.') } catch (error) { - if (error.response && error.response.data) throw error.response.data if (error.error) throw new Error(error.error) + else if (error.response && error.response.data) throw error.response.data else throw error } } @@ -186,8 +186,8 @@ class RawTransactions { throw new Error('Input must be a string or array of strings.') } catch (error) { - if (error.response && error.response.data) throw error.response.data if (error.error) throw new Error(error.error) + else if (error.response && error.response.data) throw error.response.data else throw error } } @@ -283,8 +283,8 @@ class RawTransactions { throw new Error('Input must be a string or array of strings.') } catch (error) { - if (error.response && error.response.data) throw error.response.data if (error.error) throw new Error(error.error) + else if (error.response && error.response.data) throw error.response.data else throw error } } @@ -329,8 +329,8 @@ class RawTransactions { return retArray } catch (error) { - if (error.response && error.response.data) throw error.response.data if (error.error) throw new Error(error.error) + else if (error.response && error.response.data) throw error.response.data else throw error } } @@ -383,8 +383,8 @@ class RawTransactions { return txDetails } catch (error) { - if (error.response && error.response.data) throw error.response.data if (error.error) throw new Error(error.error) + else if (error.response && error.response.data) throw error.response.data else throw error } } @@ -457,8 +457,8 @@ class RawTransactions { throw new Error('Input hex must be a string or array of strings.') } catch (error) { - if (error.response && error.response.data) throw error.response.data if (error.error) throw new Error(error.error) + else if (error.response && error.response.data) throw error.response.data else throw error } } diff --git a/test/integration/rawtransaction.js b/test/integration/rawtransaction.js index bf88216..e75e51b 100644 --- a/test/integration/rawtransaction.js +++ b/test/integration/rawtransaction.js @@ -251,9 +251,13 @@ describe('#rawtransaction', () => { describe('#_getInputAddrs', () => { it('should return an array of input addresses', async () => { // const txid = '32233db13f2ae6d82b6262f335643dccf09fc0bcfcef4bc3fbe023355f02e112' - const txid = '05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3' + const txid = + '05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3' - const txDetails = await bchjs.RawTransactions.getRawTransaction(txid, true) + const txDetails = await bchjs.RawTransactions.getRawTransaction( + txid, + true + ) const result = await bchjs.RawTransactions._getInputAddrs(txDetails) // console.log(`result: ${JSON.stringify(result, null, 2)}`) @@ -268,7 +272,8 @@ describe('#rawtransaction', () => { describe('#getTxData', () => { it('should return tx data with input addresses', async () => { - const txid = '05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3' + const txid = + '05f7d4a4e25f53d63a360434eb54f221abf159112b7fffc91da1072a079cded3' const result = await bchjs.RawTransactions.getTxData(txid) // console.log(`result: ${JSON.stringify(result, null, 2)}`)