Skip to content

Commit

Permalink
Catch NDK timeout error to replace with custom timeout error
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Dec 15, 2024
1 parent cba9700 commit 96c2baa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion wallets/nwc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Nostr from '@/lib/nostr'
import { string } from '@/lib/yup'
import { parseNwcUrl } from '@/lib/url'
import { NDKNwc } from '@nostr-dev-kit/ndk'
import { TimeoutError } from '@/lib/time'

const NWC_CONNECT_TIMEOUT_MS = 5_000

Expand Down Expand Up @@ -44,8 +45,17 @@ export async function getNwc (nwcUrl, { signal }) {
relayUrls,
secret
})

// TODO: support AbortSignal
await nwc.blockUntilReady(NWC_CONNECT_TIMEOUT_MS)
try {
await nwc.blockUntilReady(NWC_CONNECT_TIMEOUT_MS)
} catch (err) {
if (err.message === 'Timeout') {
throw new TimeoutError(NWC_CONNECT_TIMEOUT_MS)
}
throw err
}

return nwc
}

Expand Down

0 comments on commit 96c2baa

Please sign in to comment.