Skip to content

Commit

Permalink
Catch UDP errors that are thrown directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Dec 27, 2024
1 parent 1077d60 commit 0a520fb
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/nodejs/src/net/NodeJsUdpChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,22 @@ export class NodeJsUdpChannel implements UdpChannel {

async send(host: string, port: number, data: Uint8Array) {
return new Promise<void>((resolve, reject) => {
this.socket.send(data, port, host, error => {
if (error !== null) {
const netError =
error instanceof Error && "code" in error && error.code === "EHOSTUNREACH"
? new RetransmissionLimitReachedError(error.message)
: new NetworkError(error.message);
netError.stack = error.stack;
reject(netError);
return;
}
resolve();
});
try {
this.socket.send(data, port, host, error => {
if (error !== null) {
const netError =
error instanceof Error && "code" in error && error.code === "EHOSTUNREACH"
? new RetransmissionLimitReachedError(error.message)
: new NetworkError(error.message);
netError.stack = error.stack;
reject(netError);
return;
}
resolve();
});
} catch (error) {
reject(new NetworkError((error as Error).message));
}
});
}

Expand Down

0 comments on commit 0a520fb

Please sign in to comment.