aboutsummaryrefslogtreecommitdiffstats
path: root/src/json.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-06 13:18:29 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-06 13:18:29 -0500
commit9e77724efff281f0fe6d05440ad65c5ab561f380 (patch)
treeee5983d46b9f040a9c9880df9eb02b8d36956628 /src/json.rs
parentabc01f5a3865da5bd962402a8f7d9fd95c149622 (diff)
downloadrbw-9e77724efff281f0fe6d05440ad65c5ab561f380.tar.gz
rbw-9e77724efff281f0fe6d05440ad65c5ab561f380.zip
switch to thiserror
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 })
}
}