aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src/order_watcher/order_state_watcher.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-01-10 20:51:09 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-11 20:22:04 +0800
commit292c3bbff81f6e1364109981123a35b1cb32f693 (patch)
treeb609eb040272a049d0b2980bb9b103288d6f512b /packages/0x.js/src/order_watcher/order_state_watcher.ts
parent065570ebf57eb37b14ffd0b2fe131c3dcec4064a (diff)
downloaddexon-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/order_watcher/order_state_watcher.ts')
-rw-r--r--packages/0x.js/src/order_watcher/order_state_watcher.ts17
1 files changed, 14 insertions, 3 deletions
diff --git a/packages/0x.js/src/order_watcher/order_state_watcher.ts b/packages/0x.js/src/order_watcher/order_state_watcher.ts
index 9d7a733d8..3543480f8 100644
--- a/packages/0x.js/src/order_watcher/order_state_watcher.ts
+++ b/packages/0x.js/src/order_watcher/order_state_watcher.ts
@@ -155,6 +155,10 @@ export class OrderStateWatcher {
this._cleanupJobIntervalIdIfExists = intervalUtils.setAsyncExcludingInterval(
this._cleanupAsync.bind(this),
this._cleanupJobInterval,
+ (err: Error) => {
+ this.unsubscribe();
+ callback(err);
+ },
);
}
/**
@@ -207,11 +211,18 @@ export class OrderStateWatcher {
if (!_.isUndefined(this._orderByOrderHash[orderHash])) {
this.removeOrder(orderHash);
if (!_.isUndefined(this._callbackIfExists)) {
- this._callbackIfExists(orderState);
+ this._callbackIfExists(null, orderState);
}
}
}
- private async _onEventWatcherCallbackAsync(log: LogEvent): Promise<void> {
+ private async _onEventWatcherCallbackAsync(err: Error | null, logIfExists?: LogEvent): Promise<void> {
+ if (!_.isNull(err)) {
+ if (!_.isUndefined(this._callbackIfExists)) {
+ this._callbackIfExists(err);
+ this.unsubscribe();
+ }
+ }
+ const log = logIfExists as LogEvent;
const maybeDecodedLog = this._abiDecoder.tryToDecodeLogOrNoop(log);
const isLogDecoded = !_.isUndefined((maybeDecodedLog as LogWithDecodedArgs<any>).event);
if (!isLogDecoded) {
@@ -332,7 +343,7 @@ export class OrderStateWatcher {
} else {
this._orderStateByOrderHashCache[orderHash] = orderState;
}
- this._callbackIfExists(orderState);
+ this._callbackIfExists(null, orderState);
}
}
private _addToDependentOrderHashes(signedOrder: SignedOrder, orderHash: string): void {