From 394bac1c2d1a622bfd1e7550f01a5dfae1fb2850 Mon Sep 17 00:00:00 2001 From: abir Date: Wed, 20 Jan 2021 19:41:57 +0300 Subject: [PATCH] fix: logging --- packages/ws/src/Protocol/GQL/GQLProtoLayer.ts | 4 ++-- packages/ws/src/WebSocketServer.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ws/src/Protocol/GQL/GQLProtoLayer.ts b/packages/ws/src/Protocol/GQL/GQLProtoLayer.ts index 66640180..061e5b16 100644 --- a/packages/ws/src/Protocol/GQL/GQLProtoLayer.ts +++ b/packages/ws/src/Protocol/GQL/GQLProtoLayer.ts @@ -1,4 +1,4 @@ -import {assert, isFunction, isObject} from "@bunt/util"; +import {assert, isArray, isFunction, isObject} from "@bunt/util"; import {GQLClientConnection} from "./GQLClientConnection"; import { GQLClientOperation, @@ -70,7 +70,7 @@ export class GQLProtoLayer { } private isReadableError(error: unknown): error is GQLError { - return isObject(error) && "message" in error; + return isObject(error) && ("message" in error || ("errors" in error && isArray(error.errors))); } private serializeError(error: unknown): GQLError { diff --git a/packages/ws/src/WebSocketServer.ts b/packages/ws/src/WebSocketServer.ts index 73d61189..b38c3e56 100644 --- a/packages/ws/src/WebSocketServer.ts +++ b/packages/ws/src/WebSocketServer.ts @@ -213,6 +213,8 @@ export class WebSocketServer this.logger.debug("Accept connection"); ws.emit("connection", connection, req); + connection.on("error", (error) => this.logger.error(error.message, error)); + connection.on("close", () => this.logger.debug("Close connection")); setImmediate(() => this.handle(connection, async () => { const state: Record = {}; @@ -234,6 +236,7 @@ export class WebSocketServer })); }); } catch (error) { + this.logger.error(error.message, error); socket.destroy(error); } }; @@ -243,6 +246,7 @@ export class WebSocketServer await action(); connection.close(WebSocketCloseReason.NORMAL_CLOSURE); } catch (error) { + this.logger.error(error.message, error); connection.close(WebSocketCloseReason.INTERNAL_ERROR); } }