From 392136e6df2e06f4b3c06b32510a0b9d592d7e79 Mon Sep 17 00:00:00 2001 From: Cesar Rodas Date: Thu, 5 Dec 2024 20:39:40 -0300 Subject: [PATCH] Log every error in websocker worker --- crates/cdk/src/wallet/subscription/ws.rs | 38 +++++++++++++----------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/cdk/src/wallet/subscription/ws.rs b/crates/cdk/src/wallet/subscription/ws.rs index d388f396..b6cc71ac 100644 --- a/crates/cdk/src/wallet/subscription/ws.rs +++ b/crates/cdk/src/wallet/subscription/ws.rs @@ -66,25 +66,27 @@ pub async fn ws_main( loop { tracing::debug!("Connecting to {}", url); - let (ws_stream, _) = if let Ok(result) = connect_async(&url).await { - result - } else { - failure_count += 1; - if failure_count > MAX_ATTEMPT_FALLBACK_HTTP { - tracing::error!( - "Could not connect to server after {MAX_ATTEMPT_FALLBACK_HTTP} attempts, falling back to HTTP-subscription client" - ); - return fallback_to_http( - active_subscriptions.into_keys(), - http_client, - mint_url, - subscriptions, - new_subscription_recv, - on_drop, - ) - .await; + let ws_stream = match connect_async(&url).await { + Ok((ws_stream, _)) => ws_stream, + Err(err) => { + failure_count += 1; + tracing::error!("Could not connect to server: {:?}", err); + if failure_count > MAX_ATTEMPT_FALLBACK_HTTP { + tracing::error!( + "Could not connect to server after {MAX_ATTEMPT_FALLBACK_HTTP} attempts, falling back to HTTP-subscription client" + ); + return fallback_to_http( + active_subscriptions.into_keys(), + http_client, + mint_url, + subscriptions, + new_subscription_recv, + on_drop, + ) + .await; + } + continue; } - continue; }; tracing::debug!("Connected to {}", url);