From 4984e9ababc3222593e50efaafc4bf3f441b1bf9 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Tue, 30 Apr 2024 14:31:54 -0500 Subject: [PATCH] Return better NWC error code for payment failures --- mutiny-core/src/nostr/nwc.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mutiny-core/src/nostr/nwc.rs b/mutiny-core/src/nostr/nwc.rs index 92676d734..2f99d128e 100644 --- a/mutiny-core/src/nostr/nwc.rs +++ b/mutiny-core/src/nostr/nwc.rs @@ -999,6 +999,8 @@ impl NostrWalletConnect { nostr_manager.logger, "Payment timeout, not removing payment from budget" ); + + nostr_manager.save_nwc_profile(self.clone())?; } MutinyError::NonUniquePaymentHash => { log_warn!( @@ -1038,10 +1040,16 @@ impl NostrWalletConnect { } } + let code = match e { + MutinyError::InsufficientBalance => ErrorCode::InsufficientBalance, + MutinyError::PaymentTimeout => return Ok(None), // don't send error message for timeout, it can still complete + _ => ErrorCode::PaymentFailed, + }; + Response { result_type: Method::PayInvoice, error: Some(NIP47Error { - code: ErrorCode::InsufficientBalance, + code, message: format!("Failed to pay invoice: {e}"), }), result: None,