Skip to content

Commit

Permalink
Merge pull request #1159 from MutinyWallet/fedimint-errors
Browse files Browse the repository at this point in the history
Better convert fedimint errors
  • Loading branch information
TonyGiorgio authored Apr 26, 2024
2 parents 2380835 + c4041d4 commit 285fc6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 14 additions & 1 deletion mutiny-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -585,3 +586,15 @@ impl From<payjoin::send::ResponseError> for MutinyError {
Self::PayjoinResponse(e)
}
}

impl From<anyhow::Error> 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),
}
}
}
10 changes: 1 addition & 9 deletions mutiny-wasm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,7 @@ impl From<MutinyError> 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
}
Expand Down

0 comments on commit 285fc6d

Please sign in to comment.