diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-10 20:51:09 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-11 20:22:04 +0800 |
commit | 292c3bbff81f6e1364109981123a35b1cb32f693 (patch) | |
tree | b609eb040272a049d0b2980bb9b103288d6f512b /packages/0x.js/src/contract_wrappers | |
parent | 065570ebf57eb37b14ffd0b2fe131c3dcec4064a (diff) | |
download | dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.tar dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.tar.gz dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.tar.bz2 dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.tar.lz dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.tar.xz dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.tar.zst dexon-sol-tools-292c3bbff81f6e1364109981123a35b1cb32f693.zip |
Make some callbacks failable and add error handling
Diffstat (limited to 'packages/0x.js/src/contract_wrappers')
-rw-r--r-- | packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 9c4e5dfd3..27551c01d 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -167,6 +167,7 @@ export class ContractWrapper { this._blockAndLogStreamInterval = intervalUtils.setAsyncExcludingInterval( this._reconcileBlockAsync.bind(this), constants.DEFAULT_BLOCK_POLLING_INTERVAL, + this._onReconcileBlockError.bind(this), ); let isRemoved = false; this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded( @@ -177,6 +178,12 @@ export class ContractWrapper { this._onLogStateChanged.bind(this, isRemoved), ); } + private _onReconcileBlockError(err: Error): void { + const filterTokens = _.keys(this._filterCallbacks); + _.each(filterTokens, filterToken => { + this._unsubscribe(filterToken, err); + }); + } private _setNetworkId(networkId: number): void { this._networkId = networkId; } @@ -190,18 +197,11 @@ export class ContractWrapper { delete this._blockAndLogStreamerIfExists; } private async _reconcileBlockAsync(): Promise<void> { - try { - const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest); - // We need to coerce to Block type cause Web3.Block includes types for mempool blocks - if (!_.isUndefined(this._blockAndLogStreamerIfExists)) { - // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined - await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block); - } - } catch (err) { - const filterTokens = _.keys(this._filterCallbacks); - _.each(filterTokens, filterToken => { - this._unsubscribe(filterToken, err); - }); + const latestBlock = await this._web3Wrapper.getBlockAsync(BlockParamLiteral.Latest); + // We need to coerce to Block type cause Web3.Block includes types for mempool blocks + if (!_.isUndefined(this._blockAndLogStreamerIfExists)) { + // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined + await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block); } } } |