Abort payment on unexpected errors
This commit is contained in:
parent
413f76c33a
commit
517d9a9bb9
@ -39,16 +39,23 @@ export function usePaidMutation (mutation,
|
|||||||
try {
|
try {
|
||||||
return await waitForWalletPayment(walletInvoice, waitFor)
|
return await waitForWalletPayment(walletInvoice, waitFor)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
walletError = null
|
||||||
if (err instanceof WalletError) {
|
if (err instanceof WalletError) {
|
||||||
walletError = err
|
walletError = err
|
||||||
// wallet payment error handling always creates a new invoice to retry
|
// wallet payment error handling always creates a new invoice to retry
|
||||||
if (err.newInvoice) walletInvoice = err.newInvoice
|
if (err.newInvoice) walletInvoice = err.newInvoice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const invoiceError = err instanceof InvoiceCanceledError || err instanceof InvoiceExpiredError
|
||||||
|
if (!invoiceError && !walletError) {
|
||||||
|
// unexpected error, rethrow
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
|
||||||
// bail if the payment took too long to prevent showing a QR code on an unrelated page
|
// bail if the payment took too long to prevent showing a QR code on an unrelated page
|
||||||
// (if alwaysShowQROnFailure is not set) or user canceled the invoice or it expired
|
// (if alwaysShowQROnFailure is not set) or user canceled the invoice or it expired
|
||||||
const tooSlow = Date.now() - start > 1000
|
const tooSlow = Date.now() - start > 1000
|
||||||
const skipQr = (tooSlow && !alwaysShowQROnFailure) || err instanceof InvoiceCanceledError || err instanceof InvoiceExpiredError
|
const skipQr = (tooSlow && !alwaysShowQROnFailure) || invoiceError
|
||||||
if (skipQr) {
|
if (skipQr) {
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user