let (url, req) = self.api_request(Req::get(
&("accounts/".to_owned() + id)))?;
- let body = req.send()?.text()?;
- let ac: Account = match serde_json::from_str(&body) {
- Ok(ac) => Ok(ac),
- Err(e) => Err(ClientError::UrlError(url.clone(), e.to_string())),
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let ac: Account = if !rspstatus.is_success() {
+ Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
+ } else {
+ match serde_json::from_str(&rsp.text()?) {
+ Ok(ac) => Ok(ac),
+ Err(e) => Err(ClientError::UrlError(
+ url.clone(), e.to_string())),
+ }
}?;
if ac.id != id {
return Err(ClientError::UrlError(
let (url, req) = self.api_request(Req::get(
&("statuses/".to_owned() + id)))?;
- let body = req.send()?.text()?;
- let st: Status = match serde_json::from_str(&body) {
- Ok(st) => Ok(st),
- Err(e) => {
- Err(ClientError::UrlError(url.clone(), e.to_string()))
- },
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let st: Status = if !rspstatus.is_success() {
+ Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
+ } else {
+ match serde_json::from_str(&rsp.text()?) {
+ Ok(st) => Ok(st),
+ Err(e) => {
+ Err(ClientError::UrlError(url.clone(), e.to_string()))
+ },
+ }
}?;
if st.id != id {
return Err(ClientError::UrlError(
let (url, req) = self.api_request(Req::get(
&("notifications/".to_owned() + id)))?;
- let body = req.send()?.text()?;
- let not: Notification = match serde_json::from_str(&body) {
- Ok(st) => Ok(st),
- Err(e) => {
- Err(ClientError::UrlError(url.clone(), e.to_string()))
- },
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ let not: Notification = if !rspstatus.is_success() {
+ Err(ClientError::UrlError(url.clone(), rspstatus.to_string()))
+ } else {
+ match serde_json::from_str(&rsp.text()?) {
+ Ok(st) => Ok(st),
+ Err(e) => {
+ Err(ClientError::UrlError(url.clone(), e.to_string()))
+ },
+ }
}?;
if not.id != id {
return Err(ClientError::UrlError(
};
let (url, req) = self.api_request(req)?;
- let body = req.send()?.text()?;
+ let rsp = req.send()?;
+ let rspstatus = rsp.status();
+ if !rspstatus.is_success() {
+ return Err(ClientError::UrlError(
+ url.clone(), rspstatus.to_string()));
+ }
+ let body = rsp.text()?;
// Decode the JSON response as a different kind of type
// depending on the feed. But in all cases we expect to end up
};
let client = reqwest::blocking::Client::new();
- let (_url, req) = self.api_request_cl(&client, req)?;
+ let (url, req) = self.api_request_cl(&client, req)?;
let mut rsp = req.send()?;
+ let rspstatus = rsp.status();
+ if !rspstatus.is_success() {
+ return Err(ClientError::UrlError(
+ url.clone(), rspstatus.to_string()));
+ }
let id = id.clone();