Skip to content

Commit

Permalink
fix(ws): Songbird would fail if it could not deserialize ws payload.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erk- committed Apr 8, 2023
1 parent 4849043 commit 0618112
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use async_tungstenite::{
use futures::{SinkExt, StreamExt, TryStreamExt};
use serde_json::Error as JsonError;
use tokio::time::{timeout, Duration};
use tracing::instrument;
use tracing::{debug, instrument};

pub type WsStream = WebSocketStream<ConnectStream>;

Expand Down Expand Up @@ -114,7 +114,16 @@ impl SenderExt for WsStream {
#[inline]
pub(crate) fn convert_ws_message(message: Option<Message>) -> Result<Option<Event>> {
Ok(match message {
Some(Message::Text(payload)) => serde_json::from_str(&payload).map(Some)?,
Some(Message::Text(payload)) => match serde_json::from_str(&payload) {
Ok(event) => Some(event),
Err(why) => {
debug!(
"Could not deserialize websocket event, payload: {}, error: {}",
payload, why
);
None
},
},
Some(Message::Binary(bytes)) => {
return Err(Error::UnexpectedBinaryMessage(bytes));
},
Expand Down

0 comments on commit 0618112

Please sign in to comment.