Skip to content

Commit

Permalink
debug(ws): Add some debugging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulrahman1s committed Jun 28, 2022
1 parent cc2f1df commit 85de3d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/gateway/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ impl Client {
self.write.lock().await.send(payload.into()).await
}

pub async fn on_message(&mut self, content: String) -> Result<(), String> {
pub async fn on_message(&mut self, content: String) {
let payload = serde_json::from_str::<Payload>(&content);

if payload.is_err() {
Err("Invalid body".to_string())?;
log::debug!("Socket sent an invalid body");
return;
}

let payload = payload.unwrap();
Expand All @@ -51,7 +52,5 @@ impl Client {
}

log::debug!("Socket Message: {:?}", content);

Ok(())
}
}
2 changes: 1 addition & 1 deletion src/gateway/events/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub async fn run(client: &mut Client, payload: Payload) {
}

let user = if let Payload::Authenticate { token } = payload {
User::fetch_by_token(token.as_str()).await.ok()
User::fetch_by_token(token.as_str()).await
} else {
None
};
Expand Down
6 changes: 5 additions & 1 deletion src/gateway/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ async fn handle(ws: WebSocket) {

while let Some(Ok(msg)) = receiver.next().await {
if let Message::Text(content) = msg {
client.on_message(content).await.unwrap();
client.on_message(content).await;

if client.user.is_some() {
break;
} else {
log::debug!("Socket did not authenticate with valid token");
return;
}
}
}
Expand Down

0 comments on commit 85de3d9

Please sign in to comment.