catch errors on function passed to auth() and log them.
This commit is contained in:
parent
ffa7fb926e
commit
f0357805c3
|
@ -252,16 +252,20 @@ export class AbstractRelay {
|
||||||
if (this.authPromise) return this.authPromise
|
if (this.authPromise) return this.authPromise
|
||||||
|
|
||||||
this.authPromise = new Promise<string>(async (resolve, reject) => {
|
this.authPromise = new Promise<string>(async (resolve, reject) => {
|
||||||
const evt = await signAuthEvent(makeAuthEvent(this.url, challenge))
|
try {
|
||||||
const timeout = setTimeout(() => {
|
let evt = await signAuthEvent(makeAuthEvent(this.url, challenge))
|
||||||
const ep = this.openEventPublishes.get(evt.id) as EventPublishResolver
|
let timeout = setTimeout(() => {
|
||||||
if (ep) {
|
let ep = this.openEventPublishes.get(evt.id) as EventPublishResolver
|
||||||
ep.reject(new Error('auth timed out'))
|
if (ep) {
|
||||||
this.openEventPublishes.delete(evt.id)
|
ep.reject(new Error('auth timed out'))
|
||||||
}
|
this.openEventPublishes.delete(evt.id)
|
||||||
}, this.publishTimeout)
|
}
|
||||||
this.openEventPublishes.set(evt.id, { resolve, reject, timeout })
|
}, this.publishTimeout)
|
||||||
this.send('["AUTH",' + JSON.stringify(evt) + ']')
|
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
|
return this.authPromise
|
||||||
}
|
}
|
||||||
|
|
2
jsr.json
2
jsr.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.14.3",
|
"version": "2.15.0",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.14.3",
|
"version": "2.15.0",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Loading…
Reference in New Issue