From 17c34716f99616066d3a4cec3256cdc4d0b96667 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 11 Jul 2018 11:16:45 -0700 Subject: Provide subscriptionOpts in error callback and include url in error messages --- packages/connect/src/types.ts | 2 +- packages/connect/src/ws_orderbook_channel.ts | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'packages/connect') diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index 7347beb0b..fc7a4b24d 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -39,7 +39,7 @@ export interface OrderbookChannelHandler { subscriptionOpts: OrderbookChannelSubscriptionOpts, order: SignedOrder, ) => void; - onError: (channel: OrderbookChannel, err: Error) => void; + onError: (channel: OrderbookChannel, err: Error, subscriptionOpts?: OrderbookChannelSubscriptionOpts) => void; onClose: (channel: OrderbookChannel) => void; } diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts index e6a1322d2..e5d31607a 100644 --- a/packages/connect/src/ws_orderbook_channel.ts +++ b/packages/connect/src/ws_orderbook_channel.ts @@ -69,15 +69,18 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { } private _handleWebSocketMessage(message: any): void { if (_.isUndefined(message.data)) { - this._handler.onError(this, new Error(`Message does not contain utf8Data`)); + this._handler.onError(this, new Error(`Message does not contain data. Url: ${this._client.url}`)); return; } try { - const utf8Data = message.data; - const parserResult = orderbookChannelMessageParser.parse(utf8Data); + const data = message.data; + const parserResult = orderbookChannelMessageParser.parse(data); const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId]; if (_.isUndefined(subscriptionOpts)) { - this._handler.onError(this, new Error(`Message has unknown requestId: ${utf8Data}`)); + this._handler.onError( + this, + new Error(`Message has unknown requestId. Url: ${this._client.url} Message: ${data}`), + ); return; } switch (parserResult.type) { @@ -90,7 +93,11 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { break; } default: { - this._handler.onError(this, new Error(`Message has unknown type parameter: ${utf8Data}`)); + this._handler.onError( + this, + new Error(`Message has unknown type parameter. Url: ${this._client.url} Message: ${data}`), + subscriptionOpts, + ); } } } catch (error) { -- cgit v1.2.3