Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from lukasroegner/master
Browse files Browse the repository at this point in the history
Error handling for socket write
  • Loading branch information
stickpin authored May 10, 2020
2 parents cfcf0f6 + a1882e8 commit f0ba30d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions dist/lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit f0ba30d

Please sign in to comment.