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;
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<Upgraded>, chats: Chat
},
}
},
Some(Err(err)) => {
tracing::warn!("Client {sub_id} failure: {err}");
break;
}
None => {
tracing::info!("Client {sub_id} closed the socket, stopping..");
break;