Skip to content

Commit

Permalink
chore: tweak tracing in ws transport
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Mar 18, 2024
1 parent 52d16d3 commit d393405
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions crates/transport-ws/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,19 @@ pub struct WsBackend<T> {

impl<T> WsBackend<T> {
/// Handle inbound text from the websocket.
#[instrument(skip(self))]
pub async fn handle_text(&mut self, t: String) -> Result<(), ()> {
debug!(text = t, "Received message from websocket");
pub fn handle_text(&mut self, text: &str) -> Result<(), ()> {
trace!(%text, "received message from websocket");

match serde_json::from_str(&t) {
match serde_json::from_str(text) {
Ok(item) => {
trace!(?item, "Deserialized message");
let res = self.interface.send_to_frontend(item);
if res.is_err() {
error!("Failed to send message to handler");
trace!(?item, "deserialized message");
if let Err(err) = self.interface.send_to_frontend(item) {
error!(item=?err.0, "failed to send deserialized item to handler");
return Err(());
}
}
Err(err) => {
error!(%err, "Failed to deserialize message");
error!(%err, "failed to deserialize message");
return Err(());
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/transport-ws/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ impl PubSubConnect for WsConnect {

impl WsBackend<TungsteniteStream> {
/// Handle a message from the server.
pub async fn handle(&mut self, msg: Message) -> Result<(), ()> {
pub fn handle(&mut self, msg: Message) -> Result<(), ()> {
match msg {
Message::Text(text) => self.handle_text(text).await,
Message::Text(text) => self.handle_text(&text),
Message::Close(frame) => {
if frame.is_some() {
error!(?frame, "Received close frame with data");
Expand Down

0 comments on commit d393405

Please sign in to comment.