Skip to content

Commit

Permalink
Merge pull request #253 from getAlby/fix/nwc-relay-error
Browse files Browse the repository at this point in the history
fix: add custom error for nwc relay connection
  • Loading branch information
rolznz authored Sep 11, 2024
2 parents 9725cc9 + 0145b9b commit 32da4d7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/NWCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class Nip47PublishError extends Nip47Error {}
export class Nip47ResponseDecodingError extends Nip47Error {}
export class Nip47ResponseValidationError extends Nip47Error {}
export class Nip47UnexpectedResponseError extends Nip47Error {}
export class Nip47NetworkError extends Nip47Error {}

export const NWCs: Record<string, NWCOptions> = {
alby: {
Expand Down Expand Up @@ -1011,6 +1012,14 @@ export class NWCClient {
if (!this.secret) {
throw new Error("Missing secret key");
}
await this.relay.connect();
try {
await this.relay.connect();
} catch (_ /* error is always undefined */) {
console.error("failed to connect to relay", this.relayUrl);
throw new Nip47NetworkError(
"Failed to connect to " + this.relayUrl,
"OTHER",
);
}
}
}

0 comments on commit 32da4d7

Please sign in to comment.