Skip to content

Commit

Permalink
feat: use serde_path_to_error for better parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-w committed Nov 12, 2024
1 parent 647a75f commit 4f9dcdf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions edu-ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ base64 = "0.22"
hex = { version = "0.4", features = ["serde"] }
md5 = "0.7"
rand = "0.8"
serde_path_to_error = "0.1.16"

[dev-dependencies]
time = { version = "0.3", features = ["macros", "serde"] }
13 changes: 8 additions & 5 deletions edu-ws/src/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use url::Url;

use crate::{
response::{content::Section, course::Course, info::Info},
serde::{NumBool, UntaggedResultHelper},
serde::NumBool,
token::Token,
};

Expand All @@ -35,7 +35,7 @@ pub enum RequestError {
#[error(transparent)]
HttpError(#[from] reqwest::Error),
#[error(transparent)]
Decode(#[from] serde_json::Error),
Decode(#[from] serde_path_to_error::Error<serde_json::Error>),
}

impl RequestError {
Expand Down Expand Up @@ -122,10 +122,13 @@ impl Client {
.await
.unwrap();

let ret = serde_json::from_str::<'_, UntaggedResultHelper<T, Error>>(&response)
let des = &mut serde_json::Deserializer::from_str(&response);
let ret: T = serde_path_to_error::deserialize(des)
.inspect(|_| debug!(response))
.inspect_err(|err| error!(?err, response, "Could not deserialize response"))?
.0?;
.inspect_err(|err| {
debug!(response);
error!(?err, "Could not deserialize response",);
})?;

Ok(ret)
}
Expand Down

0 comments on commit 4f9dcdf

Please sign in to comment.