diff options
Diffstat (limited to 'packages/order-watcher/src')
-rw-r--r-- | packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts | 14 | ||||
-rw-r--r-- | packages/order-watcher/src/types.ts | 14 |
2 files changed, 15 insertions, 13 deletions
diff --git a/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts b/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts index f90961cc8..da5667db3 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher_websocket_server.ts @@ -105,20 +105,22 @@ export class OrderWatcherWebSocketServer { private async _onMessageCallbackAsync(connection: WebSocket.connection, message: any): Promise<void> { let response: WebSocketResponse; - assert.doesConformToSchema('message', message, schemas.orderWatcherWebSocketUtf8MessageSchema); - const request: WebSocketRequest = JSON.parse(message.utf8Data); - assert.doesConformToSchema('request', request, schemas.orderWatcherWebSocketRequestSchema); - assert.isString(request.jsonrpc, JSON_RPC_VERSION); + let id: number | null = null; try { + assert.doesConformToSchema('message', message, schemas.orderWatcherWebSocketUtf8MessageSchema); + const request: WebSocketRequest = JSON.parse(message.utf8Data); + id = request.id; + assert.doesConformToSchema('request', request, schemas.orderWatcherWebSocketRequestSchema); + assert.isString(request.jsonrpc, JSON_RPC_VERSION); response = { - id: request.id, + id, jsonrpc: JSON_RPC_VERSION, method: request.method, result: await this._routeRequestAsync(request), }; } catch (err) { response = { - id: request.id, + id, jsonrpc: JSON_RPC_VERSION, method: null, error: err.toString(), diff --git a/packages/order-watcher/src/types.ts b/packages/order-watcher/src/types.ts index 536363d8a..2b529a939 100644 --- a/packages/order-watcher/src/types.ts +++ b/packages/order-watcher/src/types.ts @@ -48,21 +48,21 @@ export enum OrderWatcherMethod { // the data field of their WebSocket message to interact with the server. export type WebSocketRequest = AddOrderRequest | RemoveOrderRequest | GetStatsRequest; -interface AddOrderRequest { +export interface AddOrderRequest { id: number; jsonrpc: string; method: OrderWatcherMethod.AddOrder; params: { signedOrder: SignedOrder }; } -interface RemoveOrderRequest { +export interface RemoveOrderRequest { id: number; jsonrpc: string; method: OrderWatcherMethod.RemoveOrder; params: { orderHash: string }; } -interface GetStatsRequest { +export interface GetStatsRequest { id: number; jsonrpc: string; method: OrderWatcherMethod.GetStats; @@ -72,21 +72,21 @@ interface GetStatsRequest { // of the WebSocket messages that the server sends out. export type WebSocketResponse = SuccessfulWebSocketResponse | ErrorWebSocketResponse; -interface SuccessfulWebSocketResponse { +export interface SuccessfulWebSocketResponse { id: number; jsonrpc: string; method: OrderWatcherMethod; result: OrderState | GetStatsResult | undefined; // result is undefined for ADD_ORDER and REMOVE_ORDER } -interface ErrorWebSocketResponse { - id: number; +export interface ErrorWebSocketResponse { + id: number | null; jsonrpc: string; method: null; error: JSONRPCError; } -interface JSONRPCError { +export interface JSONRPCError { code: number; message: string; data?: string | object; |