aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-11 03:13:15 +0800
committerFabio Berger <me@fabioberger.com>2017-11-11 03:13:15 +0800
commit4262ac3c8966468b343c6467e0e9da85ef25be05 (patch)
treebf57b46afd2967b72fc3cd6d5d11d8efa82fb3af /src/contract_wrappers
parent76b66872d8f797ee3b0efe0fa2ca914cf44ee46c (diff)
downloaddexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.tar
dexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.tar.gz
dexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.tar.bz2
dexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.tar.lz
dexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.tar.xz
dexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.tar.zst
dexon-sol-tools-4262ac3c8966468b343c6467e0e9da85ef25be05.zip
Fix unhandled promise rejection error on subscriptions
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/contract_wrapper.ts25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/contract_wrappers/contract_wrapper.ts b/src/contract_wrappers/contract_wrapper.ts
index 19dccc6f2..a02465982 100644
--- a/src/contract_wrappers/contract_wrapper.ts
+++ b/src/contract_wrappers/contract_wrapper.ts
@@ -50,10 +50,14 @@ export class ContractWrapper {
this._filterCallbacks[filterToken] = callback;
return filterToken;
}
- protected _unsubscribe(filterToken: string): void {
+ protected _unsubscribe(filterToken: string, err?: Error): void {
if (_.isUndefined(this._filters[filterToken])) {
throw new Error(ZeroExError.SubscriptionNotFound);
}
+ if (!_.isUndefined(err)) {
+ const callback = this._filterCallbacks[filterToken];
+ callback(err, undefined);
+ }
delete this._filters[filterToken];
delete this._filterCallbacks[filterToken];
if (_.isEmpty(this._filters)) {
@@ -90,7 +94,7 @@ export class ContractWrapper {
...decodedLog,
removed,
};
- this._filterCallbacks[filterToken](logEvent);
+ this._filterCallbacks[filterToken](null, logEvent);
}
});
}
@@ -122,11 +126,18 @@ export class ContractWrapper {
delete this._blockAndLogStreamer;
}
private async _reconcileBlockAsync(): Promise<void> {
- 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._blockAndLogStreamer)) {
- // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
- this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block);
+ 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._blockAndLogStreamer)) {
+ // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined
+ this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block);
+ }
+ } catch (err) {
+ const filterTokens = _.keys(this._filterCallbacks);
+ _.each(filterTokens, filterToken => {
+ this._unsubscribe(filterToken, err);
+ });
}
}
}