diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-01-13 07:51:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-13 07:51:23 +0800 |
commit | a95049450346459c5e6a211464e94fc4f702cebb (patch) | |
tree | 2cff4f477fd145f4eac897bc19d7dc0a3aecf723 /packages/0x.js/src/0x.ts | |
parent | 80a46d14beec7544849247f9362db3de3bae04a8 (diff) | |
parent | 6a56f209289105d7641c547a702469cbc9259029 (diff) | |
download | dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.tar dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.tar.gz dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.tar.bz2 dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.tar.lz dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.tar.xz dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.tar.zst dexon-sol-tools-a95049450346459c5e6a211464e94fc4f702cebb.zip |
Merge pull request #312 from 0xProject/feature/error-reporting-intervals
Better error handling on async/sync intervals
Diffstat (limited to 'packages/0x.js/src/0x.ts')
-rw-r--r-- | packages/0x.js/src/0x.ts | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 244b77a85..e1b0ef08e 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -302,26 +302,33 @@ export class ZeroEx { const txReceiptPromise = new Promise( (resolve: (receipt: TransactionReceiptWithDecodedLogs) => void, reject) => { - const intervalId = intervalUtils.setAsyncExcludingInterval(async () => { - if (timeoutExceeded) { - intervalUtils.clearAsyncExcludingInterval(intervalId); - return reject(ZeroExError.TransactionMiningTimeout); - } + const intervalId = intervalUtils.setAsyncExcludingInterval( + async () => { + if (timeoutExceeded) { + intervalUtils.clearAsyncExcludingInterval(intervalId); + return reject(ZeroExError.TransactionMiningTimeout); + } - const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); - if (!_.isNull(transactionReceipt)) { + const transactionReceipt = await this._web3Wrapper.getTransactionReceiptAsync(txHash); + if (!_.isNull(transactionReceipt)) { + intervalUtils.clearAsyncExcludingInterval(intervalId); + const logsWithDecodedArgs = _.map( + transactionReceipt.logs, + this._abiDecoder.tryToDecodeLogOrNoop.bind(this._abiDecoder), + ); + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + ...transactionReceipt, + logs: logsWithDecodedArgs, + }; + resolve(transactionReceiptWithDecodedLogArgs); + } + }, + pollingIntervalMs, + (err: Error) => { intervalUtils.clearAsyncExcludingInterval(intervalId); - const logsWithDecodedArgs = _.map( - transactionReceipt.logs, - this._abiDecoder.tryToDecodeLogOrNoop.bind(this._abiDecoder), - ); - const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { - ...transactionReceipt, - logs: logsWithDecodedArgs, - }; - resolve(transactionReceiptWithDecodedLogArgs); - } - }, pollingIntervalMs); + reject(err); + }, + ); }, ); |