diff --git a/Cargo.toml b/Cargo.toml index f029c60..324f7d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mammut" -version = "0.5.0" +version = "0.5.1" description = "A wrapper around the Mastodon API." authors = ["Aaron Power "] license = "MIT/Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index d3d8708..a37cb48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,15 +68,14 @@ macro_rules! methods { fn $method(&self, url: String) -> Result { - let result: std::result::Result = - self.client.$method(&url) + let mut response = self.client.$method(&url) .headers(self.headers.clone()) - .send()? - .json()?; + .send()?; - match result { - Ok(t) => Ok(t), - Err(error) => Err(Error::Api(error)), + if let Ok(t) = response.json::() { + Ok(t) + } else { + Err(Error::Api(response.json()?)) } } )+ @@ -100,11 +99,16 @@ macro_rules! route { )* }); - Ok(self.client.post(&self.route(concat!("/api/v1/", $url))) + let mut response = self.client.post(&self.route(concat!("/api/v1/", $url))) .headers(self.headers.clone()) .form(&form_data) - .send()? - .json()?) + .send()?; + + if let Ok(t) = response.json::<$ret>() { + Ok(t) + } else { + Err(Error::Api(response.json()?)) + } } route!{$($rest)*} };