diff --git a/src/notifications/events.rs b/src/notifications/events.rs index 3d747e5a..74b55755 100644 --- a/src/notifications/events.rs +++ b/src/notifications/events.rs @@ -15,6 +15,7 @@ pub enum WebSocketError { InvalidSession, OnboardingNotFinished, AlreadyAuthenticated, + MalformedData { msg: String }, } #[derive(Deserialize, Debug)] diff --git a/src/notifications/websocket.rs b/src/notifications/websocket.rs index 64373cee..b8831942 100644 --- a/src/notifications/websocket.rs +++ b/src/notifications/websocket.rs @@ -74,7 +74,20 @@ async fn accept(stream: TcpStream) { let incoming = read.try_for_each(async move |msg| { let mutex = mutex_generator(); if let Message::Text(text) = msg { - if let Ok(notification) = serde_json::from_str::(&text) { + let maybe_decoded = serde_json::from_str::(&text); + + // If serde fails to decode the data, return a `MalformedData` error + if let Err(why) = maybe_decoded { + send(ClientboundNotification::Error( + WebSocketError::MalformedData { + msg: why.to_string() + } + )); + + return Ok(()); + } + + if let Ok(notification) = maybe_decoded { match notification { ServerboundNotification::Authenticate(auth) => { {