diff --git a/mutiny-core/src/error.rs b/mutiny-core/src/error.rs index 2ccee84d8..1f33e3bee 100644 --- a/mutiny-core/src/error.rs +++ b/mutiny-core/src/error.rs @@ -8,6 +8,7 @@ use lightning::ln::peer_handler::PeerHandleError; use lightning_invoice::ParseOrSemanticError; use lightning_rapid_gossip_sync::GraphSyncError; use lightning_transaction_sync::TxSyncError; +use log::error; use nostr::nips::nip05; use std::string::FromUtf8Error; use thiserror::Error; @@ -179,7 +180,7 @@ pub enum MutinyError { #[error("Failed to connect to a federation.")] FederationConnectionFailed, #[error(transparent)] - Other(#[from] anyhow::Error), + Other(anyhow::Error), } #[derive(Error, Debug)] @@ -585,3 +586,15 @@ impl From for MutinyError { Self::PayjoinResponse(e) } } + +impl From for MutinyError { + fn from(e: anyhow::Error) -> Self { + error!("Got unhandled error: {e}"); + // handle fedimint anyhow errors + match e.to_string().as_str() { + "Insufficient balance" => Self::InsufficientBalance, + "MissingInvoiceAmount" => Self::BadAmountError, + _ => Self::Other(e), + } + } +} diff --git a/mutiny-wasm/src/error.rs b/mutiny-wasm/src/error.rs index d058c7826..3e7b70ff8 100644 --- a/mutiny-wasm/src/error.rs +++ b/mutiny-wasm/src/error.rs @@ -228,15 +228,7 @@ impl From for MutinyJsError { MutinyError::TokenAlreadySpent => MutinyJsError::TokenAlreadySpent, MutinyError::FederationRequired => MutinyJsError::FederationRequired, MutinyError::FederationConnectionFailed => MutinyJsError::FederationConnectionFailed, - MutinyError::Other(e) => { - error!("Got unhandled error: {e}"); - // FIXME: For some unknown reason, InsufficientBalance is being returned as `Other` - if e.to_string().starts_with("Insufficient balance") { - MutinyJsError::InsufficientBalance - } else { - MutinyJsError::UnknownError - } - } + MutinyError::Other(_) => MutinyJsError::UnknownError, MutinyError::SubscriptionClientNotConfigured => { MutinyJsError::SubscriptionClientNotConfigured }