- if (this.responseHandlers.has(responseId)) {
- const ws = this.responseHandlers.get(responseId) as WebSocket;
- if (ws?.readyState === WebSocket.OPEN) {
- ws.send(JSON.stringify(response));
+ try {
+ if (this.responseHandlers.has(responseId)) {
+ const ws = this.responseHandlers.get(responseId) as WebSocket;
+ if (ws?.readyState === WebSocket.OPEN) {
+ ws.send(JSON.stringify(response));
+ } else {
+ logger.error(
+ `${this.logPrefix(
+ moduleName,
+ 'sendResponse'
+ )} Error at sending response id '${responseId}', WebSocket is not open: ${
+ ws?.readyState
+ }`
+ );
+ }
+ } else {
+ logger.error(
+ `${this.logPrefix(
+ moduleName,
+ 'sendResponse'
+ )} Response for unknown request id: ${responseId}`
+ );