Skip to content

Commit

Permalink
fix(backend): add more error handling in socket_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenclaw900 committed Jan 30, 2022
1 parent d88cba4 commit 172a6e0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/backend/src/sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,26 @@ pub async fn socket_handler(socket: warp::ws::WebSocket) {
if data.is_close() {
break;
}
req = DeJson::deserialize_json(data.to_str().unwrap()).unwrap();
let data_str;
match data.to_str() {
Ok(data_string) => data_str = data_string,
Err(_) => {
log::error!("Couldn't convert received data to text");
continue;
}
}
req = match DeJson::deserialize_json(data_str) {
Ok(json) => json,
Err(_) => {
log::error!("Couldn't parse JSON");
continue;
}
};
if CONFIG.pass && !shared::validate_token(&req.token) {
if !first_message {
data_send.send(None).await.unwrap();
if data_send.send(None).await.is_err() {
break;
}
}
data_send
.send(Some(shared::Request {
Expand Down

0 comments on commit 172a6e0

Please sign in to comment.