Skip to content

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 76ae9cc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 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,18 @@ 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 76ae9cc

Please sign in to comment.