catch errors on function passed to auth() and log them.

This commit is contained in:
fiatjaf 2025-06-10 10:16:50 -03:00
parent ffa7fb926e
commit f0357805c3
3 changed files with 16 additions and 12 deletions

View File

@ -252,16 +252,20 @@ export class AbstractRelay {
if (this.authPromise) return this.authPromise
this.authPromise = new Promise<string>(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
}

View File

@ -1,6 +1,6 @@
{
"name": "@nostr/tools",
"version": "2.14.3",
"version": "2.15.0",
"exports": {
".": "./index.ts",
"./core": "./core.ts",

View File

@ -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",