Improve error handling when trying to forward to incompatible server

This commit is contained in:
Marcin Kulik
2025-01-21 15:14:10 +01:00
parent cd8ce618c6
commit f0f908872c

View File

@@ -70,12 +70,31 @@ pub async fn forward(
tungstenite::error::ProtocolError::SecWebSocketSubProtocolError(_), tungstenite::error::ProtocolError::SecWebSocketSubProtocolError(_),
)) = e.downcast_ref::<tungstenite::error::Error>() )) = e.downcast_ref::<tungstenite::error::Error>()
{ {
// This happens when the server accepts the websocket connection
// but doesn't properly perform the protocol negotiation.
// This applies to asciinema-server v20241103 and earlier.
let _ = notifier_tx let _ = notifier_tx
.send("CLI not compatible with the server, forwarding failed".to_string()); .send("The server version is too old, forwarding failed".to_string());
break; break;
} }
if let Some(tungstenite::error::Error::Http(response)) =
e.downcast_ref::<tungstenite::error::Error>()
{
if response.status().as_u16() == 400 {
// This happens when the server doesn't support our protocol (version).
// This applies to asciinema-server versions newer than v20241103.
let _ = notifier_tx.send(
"CLI not compatible with the server, forwarding failed".to_string(),
);
break;
}
}
error!("connection error: {e}"); error!("connection error: {e}");
if reconnect_attempt == 0 { if reconnect_attempt == 0 {