Wrap promises with try blocks

This commit is contained in:
Ross Savage
2024-02-06 20:25:50 +01:00
parent 0379597d5e
commit aec144693d
17 changed files with 275 additions and 145 deletions

View File

@@ -5,12 +5,16 @@ import {
const exampleSendSpontaneousPayment = async () => {
// ANCHOR: send-spontaneous-payment
const nodeId = '...'
try {
const nodeId = '...'
const sendPaymentResponse = await sendSpontaneousPayment({
nodeId,
amountMsat: 3000000
})
const sendPaymentResponse = await sendSpontaneousPayment({
nodeId,
amountMsat: 3000000
})
} catch (err) {
console.error(err)
}
// ANCHOR_END: send-spontaneous-payment
}
@@ -24,15 +28,19 @@ const stringToBytes = (str: string): number[] => {
const exampleSendSpontaneousPaymentWithTlvs = async () => {
// ANCHOR: send-spontaneous-payment-with-tlvs
const nodeId = '...'
const extraTlvs: TlvEntry[] = [
{ fieldNumber: 34349334, value: stringToBytes('Hello world!') }
]
try {
const nodeId = '...'
const extraTlvs: TlvEntry[] = [
{ fieldNumber: 34349334, value: stringToBytes('Hello world!') }
]
const sendPaymentResponse = await sendSpontaneousPayment({
nodeId,
amountMsat: 3000000,
extraTlvs
})
const sendPaymentResponse = await sendSpontaneousPayment({
nodeId,
amountMsat: 3000000,
extraTlvs
})
} catch (err) {
console.error(err)
}
// ANCHOR_END: send-spontaneous-payment-with-tlvs
}