fixed error handling.

master
Aaron Power 8 years ago
parent 2dd0c83b55
commit d36c861c19
  1. 2
      Cargo.toml
  2. 24
      src/lib.rs

@ -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 <theaaronepower@gmail.com>"]
license = "MIT/Apache-2.0"

@ -68,15 +68,14 @@ macro_rules! methods {
fn $method<T: serde::Deserialize>(&self, url: String)
-> Result<T>
{
let result: std::result::Result<T, ApiError> =
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::<T>() {
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)*}
};

Loading…
Cancel
Save