diff --git a/dist/lib/connection.js b/dist/lib/connection.js index d798118..805916e 100644 --- a/dist/lib/connection.js +++ b/dist/lib/connection.js @@ -149,13 +149,25 @@ class Connection extends typed_events_1.default { that.emit('debug', "DEBUG: >>>> Send Protobuf=" + JSON.stringify(message.toJSON(), null, 2)); let messageLength = Buffer.from(varint.encode(encrypted.length)); let bytes = Buffer.concat([messageLength, encrypted]); - that.socket.write(bytes); + try { + that.socket.write(bytes); + } catch (e) { + that.emit('debug', "DEBUG: >>>> Error while writing to socket"); + reject(); + return; + } } else { that.emit('debug', "DEBUG: >>>> Send Protobuf=" + JSON.stringify(message.toJSON(), null, 2)); let messageLength = Buffer.from(varint.encode(data.length)); let bytes = Buffer.concat([messageLength, data]); - that.socket.write(bytes); + try { + that.socket.write(bytes); + } catch (e) { + that.emit('debug', "DEBUG: >>>> Error while writing to socket"); + reject(); + return; + } } if (!waitForResponse) { resolve(new message_1.Message(message));