Skip to content

Commit

Permalink
fix: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
izatop committed Jan 20, 2021
1 parent ec3bff4 commit 394bac1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ws/src/Protocol/GQL/GQLProtoLayer.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions packages/ws/src/WebSocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ export class WebSocketServer<C extends IContext>

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<string, any> = {};
Expand All @@ -234,6 +236,7 @@ export class WebSocketServer<C extends IContext>
}));
});
} catch (error) {
this.logger.error(error.message, error);
socket.destroy(error);
}
};
Expand All @@ -243,6 +246,7 @@ export class WebSocketServer<C extends IContext>
await action();
connection.close(WebSocketCloseReason.NORMAL_CLOSURE);
} catch (error) {
this.logger.error(error.message, error);
connection.close(WebSocketCloseReason.INTERNAL_ERROR);
}
}
Expand Down

0 comments on commit 394bac1

Please sign in to comment.