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

Commit 285fc6d

Browse files
Merge pull request #1159 from MutinyWallet/fedimint-errors
Better convert fedimint errors
2 parents 2380835 + c4041d4 commit 285fc6d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

mutiny-core/src/error.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use lightning::ln::peer_handler::PeerHandleError;
88
use lightning_invoice::ParseOrSemanticError;
99
use lightning_rapid_gossip_sync::GraphSyncError;
1010
use lightning_transaction_sync::TxSyncError;
11+
use log::error;
1112
use nostr::nips::nip05;
1213
use std::string::FromUtf8Error;
1314
use thiserror::Error;
@@ -179,7 +180,7 @@ pub enum MutinyError {
179180
#[error("Failed to connect to a federation.")]
180181
FederationConnectionFailed,
181182
#[error(transparent)]
182-
Other(#[from] anyhow::Error),
183+
Other(anyhow::Error),
183184
}
184185

185186
#[derive(Error, Debug)]
@@ -585,3 +586,15 @@ impl From<payjoin::send::ResponseError> for MutinyError {
585586
Self::PayjoinResponse(e)
586587
}
587588
}
589+
590+
impl From<anyhow::Error> for MutinyError {
591+
fn from(e: anyhow::Error) -> Self {
592+
error!("Got unhandled error: {e}");
593+
// handle fedimint anyhow errors
594+
match e.to_string().as_str() {
595+
"Insufficient balance" => Self::InsufficientBalance,
596+
"MissingInvoiceAmount" => Self::BadAmountError,
597+
_ => Self::Other(e),
598+
}
599+
}
600+
}

mutiny-wasm/src/error.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,7 @@ impl From<MutinyError> for MutinyJsError {
228228
MutinyError::TokenAlreadySpent => MutinyJsError::TokenAlreadySpent,
229229
MutinyError::FederationRequired => MutinyJsError::FederationRequired,
230230
MutinyError::FederationConnectionFailed => MutinyJsError::FederationConnectionFailed,
231-
MutinyError::Other(e) => {
232-
error!("Got unhandled error: {e}");
233-
// FIXME: For some unknown reason, InsufficientBalance is being returned as `Other`
234-
if e.to_string().starts_with("Insufficient balance") {
235-
MutinyJsError::InsufficientBalance
236-
} else {
237-
MutinyJsError::UnknownError
238-
}
239-
}
231+
MutinyError::Other(_) => MutinyJsError::UnknownError,
240232
MutinyError::SubscriptionClientNotConfigured => {
241233
MutinyJsError::SubscriptionClientNotConfigured
242234
}

0 commit comments

Comments
 (0)