Skip to content

Commit

Permalink
make code more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Jan 6, 2025
1 parent f5761d1 commit ab6676c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions wallets/zebedee/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ export async function testSendPayment ({ apiKey }, { signal }) {

export async function sendPayment (bolt11, { apiKey }, { signal }) {
const res = await apiCall('payments', { body: { invoice: bolt11 }, apiKey }, { signal })
const { id, preimage } = res?.data
if (!res?.data) throw new Error('payment failed')

const { id, preimage } = res.data
if (preimage) return preimage

// the api might return before the invoice is paid, so we'll wait for the preimage
return await waitForPreimage(id, { apiKey }, { signal })
}
Expand Down Expand Up @@ -59,8 +62,10 @@ export async function apiCall (api, { body, apiKey, method = 'POST' }, { signal
} catch (e) {
console.log('failed to parse error', e)
}

// throw the error, if we don't have one, we try to use the request status
throw new Error(error ?? (res.statusText || `error ${res.status}`))
if (!error) error = res.statusText || `error ${res.status}`
throw new Error(error)
}

assertContentTypeJson(res)
Expand Down

0 comments on commit ab6676c

Please sign in to comment.