aboutsummaryrefslogtreecommitdiffstats
path: root/src/json.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/json.rs')
-rw-r--r--src/json.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/json.rs b/src/json.rs
index 2816a1f..d6c5328 100644
--- a/src/json.rs
+++ b/src/json.rs
@@ -7,15 +7,18 @@ pub trait DeserializeJsonWithPath {
impl DeserializeJsonWithPath for String {
fn json_with_path<T: serde::de::DeserializeOwned>(self) -> Result<T> {
let jd = &mut serde_json::Deserializer::from_str(&self);
- serde_path_to_error::deserialize(jd).context(crate::error::JSON)
+ serde_path_to_error::deserialize(jd)
+ .map_err(|source| Error::JSON { source })
}
}
impl DeserializeJsonWithPath for reqwest::blocking::Response {
fn json_with_path<T: serde::de::DeserializeOwned>(self) -> Result<T> {
- let bytes = self.bytes().context(crate::error::Reqwest)?;
+ let bytes =
+ self.bytes().map_err(|source| Error::Reqwest { source })?;
let jd = &mut serde_json::Deserializer::from_slice(&bytes);
- serde_path_to_error::deserialize(jd).context(crate::error::JSON)
+ serde_path_to_error::deserialize(jd)
+ .map_err(|source| Error::JSON { source })
}
}
@@ -31,8 +34,12 @@ impl DeserializeJsonWithPathAsync for reqwest::Response {
async fn json_with_path<T: serde::de::DeserializeOwned>(
self,
) -> Result<T> {
- let bytes = self.bytes().await.context(crate::error::Reqwest)?;
+ let bytes = self
+ .bytes()
+ .await
+ .map_err(|source| Error::Reqwest { source })?;
let jd = &mut serde_json::Deserializer::from_slice(&bytes);
- serde_path_to_error::deserialize(jd).context(crate::error::JSON)
+ serde_path_to_error::deserialize(jd)
+ .map_err(|source| Error::JSON { source })
}
}