From de7e956c6e06c473613f254ca04e257af3e1da91 Mon Sep 17 00:00:00 2001 From: Paweł Dybiec Date: Sun, 25 Dec 2022 21:13:52 +0000 Subject: Parse json response from server --- src/mattermost.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/mattermost.rs') diff --git a/src/mattermost.rs b/src/mattermost.rs index 7742e3e..a062887 100644 --- a/src/mattermost.rs +++ b/src/mattermost.rs @@ -2,7 +2,7 @@ use anyhow::anyhow; use async_tungstenite::{tokio::connect_async, tungstenite::Message}; use futures_util::{SinkExt, StreamExt}; use serde_json::json; -use tracing::debug; +use tracing::{debug, warn}; pub struct AuthData { pub(crate) login: String, pub(crate) password: String, @@ -56,7 +56,22 @@ impl Client { )) .await?; while let Some(message) = ws_stream.next().await { - debug!("{:?}", message); + match message { + Ok(message) => match message { + Message::Text(text) => { + let json: Result = serde_json::from_str(&text); + match json { + Ok(json) => debug!("Got json {json}"), + Err(err) => warn!("Error while deserializing {err}"), + } + } + Message::Close(_) => break, + _ => { + debug!("Message {message:?}"); + } + }, + Err(err) => warn!("Error {err} while reading message"), + } } Ok(()) } -- cgit 1.4.1