From f0357805c3ab41a63f1eed42f15f0991a6e1c3be Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 10 Jun 2025 10:16:50 -0300 Subject: [PATCH] catch errors on function passed to auth() and log them. --- abstract-relay.ts | 24 ++++++++++++++---------- jsr.json | 2 +- package.json | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/abstract-relay.ts b/abstract-relay.ts index 454feee..631bfdb 100644 --- a/abstract-relay.ts +++ b/abstract-relay.ts @@ -252,16 +252,20 @@ export class AbstractRelay { if (this.authPromise) return this.authPromise this.authPromise = new Promise(async (resolve, reject) => { - const evt = await signAuthEvent(makeAuthEvent(this.url, challenge)) - const timeout = setTimeout(() => { - const ep = this.openEventPublishes.get(evt.id) as EventPublishResolver - if (ep) { - ep.reject(new Error('auth timed out')) - this.openEventPublishes.delete(evt.id) - } - }, this.publishTimeout) - this.openEventPublishes.set(evt.id, { resolve, reject, timeout }) - this.send('["AUTH",' + JSON.stringify(evt) + ']') + try { + let evt = await signAuthEvent(makeAuthEvent(this.url, challenge)) + let timeout = setTimeout(() => { + let ep = this.openEventPublishes.get(evt.id) as EventPublishResolver + if (ep) { + ep.reject(new Error('auth timed out')) + this.openEventPublishes.delete(evt.id) + } + }, this.publishTimeout) + this.openEventPublishes.set(evt.id, { resolve, reject, timeout }) + this.send('["AUTH",' + JSON.stringify(evt) + ']') + } catch (err) { + console.warn('subscribe auth function failed:', err) + } }) return this.authPromise } diff --git a/jsr.json b/jsr.json index 63e76d4..e4b7307 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@nostr/tools", - "version": "2.14.3", + "version": "2.15.0", "exports": { ".": "./index.ts", "./core": "./core.ts", diff --git a/package.json b/package.json index 890dd85..7ff8f86 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "nostr-tools", - "version": "2.14.3", + "version": "2.15.0", "description": "Tools for making a Nostr client.", "repository": { "type": "git",