From 03b0ababa792616d35cff0945dd2ca437606a3e8 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Tue, 31 Jan 2023 22:30:55 +0100 Subject: [PATCH] handle client-side ws error --- src/http/ws.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/http/ws.rs b/src/http/ws.rs index 41d70ab..9ee668a 100644 --- a/src/http/ws.rs +++ b/src/http/ws.rs @@ -38,8 +38,7 @@ async fn handle_connection(mut ws_stream: WebSocketStream, chats: Chat biased; msg = ws_stream.next() => { match msg { - Some(msg) => { - let msg = msg.unwrap(); + Some(Ok(msg)) => { let txt = msg.to_text().unwrap().to_string(); tracing::info!("Received a message: {txt}, sub_id={sub_id}"); match chats.broadcast(format!("{sub_id}: {txt}").as_str()).await { @@ -49,6 +48,10 @@ async fn handle_connection(mut ws_stream: WebSocketStream, chats: Chat }, } }, + Some(Err(err)) => { + tracing::warn!("Client {sub_id} failure: {err}"); + break; + } None => { tracing::info!("Client {sub_id} closed the socket, stopping.."); break;