Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Return better NWC error code for payment failures
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed May 8, 2024
1 parent cb64198 commit 4984e9a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mutiny-core/src/nostr/nwc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 4984e9a

Please sign in to comment.