Skip to content

Commit 533037e

Browse files
committed
chore: fallback to http strategy if websocket fails on open
1 parent 66eec26 commit 533037e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/transport/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ impl DatabaseConnection {
102102
let http = HttpStrategy::new(reqwest_client, turso_config.clone());
103103
let mut websocket = WebSocketStrategy::new(turso_config.clone());
104104

105-
websocket.connect().await?;
106-
107-
if cfg!(debug_assertions) {
108-
println!("WebSocket connection established for {}", db_name);
109-
}
105+
let connection = websocket.connect().await;
106+
let strategy: ActiveStrategy = match connection {
107+
Ok(_) => ActiveStrategy::Websocket,
108+
Err(err) => {
109+
if cfg!(debug_assertions) {
110+
println!("WebSocket connection failed: {}", err);
111+
}
112+
ActiveStrategy::Http
113+
}
114+
};
110115

111116
Ok(Self {
112117
http,
113118
websocket,
114-
strategy: ActiveStrategy::Websocket,
119+
strategy,
115120
})
116121
}
117122

0 commit comments

Comments
 (0)