diff options
author | Vincent Ambo <tazjin@gmail.com> | 2018-06-17T01·46+0200 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2018-06-17T13·46+0200 |
commit | 68189d4872fcd2f9ba23c168a534b8bce2f26bb5 (patch) | |
tree | 7323d4804244d0700e7e364ff52619591416351b /src/main.rs | |
parent | 87ab3c806c40d565b75c18237494d591282ccbc2 (diff) |
refactor(main): Log error responses from Stackdriver
In some cases Stackdriver seems to return error responses for batched inserts. This change will log the error response body and status from Stackdriver for all insertion errors.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index f6c4ea0d9060..7a032f98f3e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ //! * TODO 2018-06-15: Extract timestamps from journald instead of //! relying on ingestion timestamps. +#[macro_use] extern crate failure; #[macro_use] extern crate hyper; #[macro_use] extern crate log; #[macro_use] extern crate serde_derive; @@ -42,7 +43,6 @@ extern crate chrono; extern crate env_logger; -extern crate failure; extern crate reqwest; extern crate serde; extern crate systemd; @@ -386,13 +386,17 @@ fn prepare_request(entries: &[LogEntry]) -> Value { /// Perform the log entry insertion in Stackdriver Logging. fn write_entries(client: &Client, token: &Token, request: Value) -> Result<()> { - client.post(ENTRIES_WRITE_URL) + let mut response = client.post(ENTRIES_WRITE_URL) .header(header::Authorization(format!("Bearer {}", token.token))) .json(&request) - .send()? - .error_for_status()?; + .send()?; - Ok(()) + if response.status().is_success() { + Ok(()) + } else { + let body = response.text().unwrap_or_else(|_| "no response body".into()); + bail!("{} ({})", body, response.status()) + } } /// Attempt to read the initial cursor position from the configured |