From fdf3998534b2ca34a768b91479724fe9393707ae Mon Sep 17 00:00:00 2001 From: Juan P Lopez Date: Fri, 16 Aug 2024 13:41:09 -0500 Subject: [PATCH] fix(core): add lnd FeeInsufficient error validation --- core/api/src/domain/bitcoin/lightning/errors.ts | 1 + core/api/src/graphql/error-map.ts | 5 +++++ core/api/src/services/lnd/errors.ts | 1 + core/api/src/services/lnd/index.ts | 3 +++ 4 files changed, 10 insertions(+) diff --git a/core/api/src/domain/bitcoin/lightning/errors.ts b/core/api/src/domain/bitcoin/lightning/errors.ts index 0f8ab8fd23..e4124b827b 100644 --- a/core/api/src/domain/bitcoin/lightning/errors.ts +++ b/core/api/src/domain/bitcoin/lightning/errors.ts @@ -39,6 +39,7 @@ export class RouteNotFoundError extends LightningServiceError {} export class UnknownNextPeerError extends LightningServiceError {} export class InsufficientBalanceForRoutingError extends LightningServiceError {} export class InsufficientBalanceForLnPaymentError extends LightningServiceError {} +export class InsufficientFeeForLnPaymentError extends LightningServiceError {} export class InvoiceExpiredOrBadPaymentHashError extends LightningServiceError {} export class PaymentRejectedByDestinationError extends LightningServiceError {} export class PaymentAttemptsTimedOutError extends LightningServiceError {} diff --git a/core/api/src/graphql/error-map.ts b/core/api/src/graphql/error-map.ts index 25db3d2d53..5de6d982dd 100644 --- a/core/api/src/graphql/error-map.ts +++ b/core/api/src/graphql/error-map.ts @@ -407,6 +407,11 @@ export const mapError = (error: ApplicationError): CustomGraphQLError => { message = error.message return new InsufficientBalanceError({ message, logger: baseLogger }) + case "InsufficientFeeForLnPaymentError": + message = + "Payment failed due to an insufficient fee, please try again later or contact support if the problem persists." + return new ValidationInternalError({ message, logger: baseLogger }) + case "CaptchaUserFailToPassError": message = "Captcha validation failed." return new ValidationInternalError({ message, logger: baseLogger }) diff --git a/core/api/src/services/lnd/errors.ts b/core/api/src/services/lnd/errors.ts index d7b5d918b7..e115c5f641 100644 --- a/core/api/src/services/lnd/errors.ts +++ b/core/api/src/services/lnd/errors.ts @@ -2,6 +2,7 @@ export const KnownLndErrorDetails = { // Off-chain InsufficientBalance: /insufficient local balance/, InsufficientBalanceToAttemptPayment: /InsufficientBalanceToAttemptPayment/, + InsufficientFee: /FeeInsufficient/, InvoiceNotFound: /unable to locate invoice/, InvoiceAlreadyPaid: /invoice is already paid/, UnableToFindRoute: /PaymentPathfindingFailedToFindPossibleRoute/, diff --git a/core/api/src/services/lnd/index.ts b/core/api/src/services/lnd/index.ts index 02f5f036d6..1a55ff8b3a 100644 --- a/core/api/src/services/lnd/index.ts +++ b/core/api/src/services/lnd/index.ts @@ -78,6 +78,7 @@ import { decodeInvoice, InvalidInvoiceAmountError, InvoiceAlreadySettledError, + InsufficientFeeForLnPaymentError, } from "@/domain/bitcoin/lightning" import { CacheKeys } from "@/domain/cache" import { LnFees } from "@/domain/payments" @@ -1208,6 +1209,8 @@ const handleSendPaymentLndErrors = ({ return new InsufficientBalanceForLnPaymentError() case match(KnownLndErrorDetails.FeaturePairExists): return new InvalidFeatureBitsForLndInvoiceError() + case match(KnownLndErrorDetails.InsufficientFee): + return new InsufficientFeeForLnPaymentError() default: return handleCommonLightningServiceErrors(err)