Remove TODO about errors in createInvoice (#1300)

This commit is contained in:
ekzyis 2024-08-14 14:56:02 -05:00 committed by GitHub
parent 4000522773
commit 8e18fa0760
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 19 deletions

View File

@ -11,6 +11,7 @@ export const createInvoice = async (
{ msats, description, descriptionHash, expiry }, { msats, description, descriptionHash, expiry },
{ cert, macaroon, socket } { cert, macaroon, socket }
) => { ) => {
try {
const { lnd } = await authenticatedLndGrpc({ const { lnd } = await authenticatedLndGrpc({
cert, cert,
macaroon, macaroon,
@ -26,4 +27,9 @@ export const createInvoice = async (
}) })
return invoice.request return invoice.request
} catch (err) {
// LND errors can be in this shape: [code, type, { err: { code, details, metadata } }]
const details = err[2]?.err?.details || err.message || err.toString?.()
throw new Error(details)
}
} }

View File

@ -59,15 +59,10 @@ export async function createInvoice (userId, { msats, description, descriptionHa
return { invoice, wallet } return { invoice, wallet }
} catch (error) { } catch (error) {
console.error(error) console.error(error)
// TODO: I think this is a bug, `createInvoice` should parse the error
// LND errors are in this shape: [code, type, { err: { code, details, metadata } }]
const details = error[2]?.err?.details || error.message || error.toString?.()
await addWalletLog({ await addWalletLog({
wallet, wallet,
level: 'ERROR', level: 'ERROR',
message: `creating invoice for ${description ?? ''} failed: ` + details message: `creating invoice for ${description ?? ''} failed: ` + error
}, { models }) }, { models })
} }
} }