forked from lavina/lavina
1
0
Fork 0

handle client-side ws error

This commit is contained in:
Nikita Vilunov 2023-01-31 22:30:55 +01:00
parent dd8cf0fbf0
commit 03b0ababa7
1 changed files with 5 additions and 2 deletions

View File

@ -38,8 +38,7 @@ async fn handle_connection(mut ws_stream: WebSocketStream<Upgraded>, chats: Chat
biased; biased;
msg = ws_stream.next() => { msg = ws_stream.next() => {
match msg { match msg {
Some(msg) => { Some(Ok(msg)) => {
let msg = msg.unwrap();
let txt = msg.to_text().unwrap().to_string(); let txt = msg.to_text().unwrap().to_string();
tracing::info!("Received a message: {txt}, sub_id={sub_id}"); tracing::info!("Received a message: {txt}, sub_id={sub_id}");
match chats.broadcast(format!("{sub_id}: {txt}").as_str()).await { match chats.broadcast(format!("{sub_id}: {txt}").as_str()).await {
@ -49,6 +48,10 @@ async fn handle_connection(mut ws_stream: WebSocketStream<Upgraded>, chats: Chat
}, },
} }
}, },
Some(Err(err)) => {
tracing::warn!("Client {sub_id} failure: {err}");
break;
}
None => { None => {
tracing::info!("Client {sub_id} closed the socket, stopping.."); tracing::info!("Client {sub_id} closed the socket, stopping..");
break; break;