Verified Commit b4133126 authored by Maxime Buquet's avatar Maxime Buquet
Browse files

chronophage example: Display response body error when available


Signed-off-by: Maxime Buquet's avatarMaxime “pep” Buquet <pep@bouah.net>
parent c60d427b
......@@ -21,13 +21,13 @@ use timelog::types::{
ChronophageDay, ChronophageDays, Task, TimelogDay, TimelogEntry, TimesheetDay,
};
use reqwest::{header::USER_AGENT, Error as ReqwestError, Response};
use reqwest::header::USER_AGENT;
fn push_timesheets<D: Into<ChronophageDays>>(
user: &str,
password: &str,
days: D,
) -> Result<Response, ReqwestError> {
) -> Result<(), String> {
let days = days.into();
let server_url = "https://dev.chronophage.collabora.com";
let api_endpoint = "/timesheet";
......@@ -38,8 +38,17 @@ fn push_timesheets<D: Into<ChronophageDays>>(
.header(USER_AGENT, "timelog-rs")
.basic_auth(user, Some(password))
.form(&days)
.send()?;
Ok(res)
.send();
if let Ok(mut res) = res {
if ! res.status().is_success() {
if let Ok(text) = res.text() {
return Err(text);
}
}
}
Ok(())
}
fn main() {
......@@ -121,6 +130,10 @@ fn main() {
println!("Foo1: {:?}", days);
if let Ok(days) = days {
push_timesheets(user, password, days);
if let Err(text) = push_timesheets(user, password, days) {
println!("An error occured, please check your timelogs:\n{}", text);
} else {
println!("Timelogs successfully uploaded.");
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment