log API responses

master
Paul Woolcock 6 years ago
parent 205a98a8c2
commit 97cadbfd3c
  1. 1
      Cargo.toml
  2. 8
      src/lib.rs

@ -24,6 +24,7 @@ try_from = "0.3.2"
toml = { version = "0.5.0", optional = true } toml = { version = "0.5.0", optional = true }
hyper-old-types = "0.11.0" hyper-old-types = "0.11.0"
envy = { version = "0.4.0", optional = true } envy = { version = "0.4.0", optional = true }
log = "0.4.6"
[dependencies.chrono] [dependencies.chrono]
version = "0.4" version = "0.4"

@ -72,6 +72,8 @@
)] )]
#![allow(intra_doc_link_resolution_failure)] #![allow(intra_doc_link_resolution_failure)]
#[macro_use]
extern crate log;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use] #[macro_use]
@ -729,10 +731,14 @@ fn deserialise<T: for<'de> serde::Deserialize<'de>>(response: Response) -> Resul
let mut reader = Tap::new(response); let mut reader = Tap::new(response);
match serde_json::from_reader(&mut reader) { match serde_json::from_reader(&mut reader) {
Ok(t) => Ok(t), Ok(t) => {
debug!("{}", String::from_utf8_lossy(&reader.bytes));
Ok(t)
},
// If deserializing into the desired type fails try again to // If deserializing into the desired type fails try again to
// see if this is an error response. // see if this is an error response.
Err(e) => { Err(e) => {
error!("{}", String::from_utf8_lossy(&reader.bytes));
if let Ok(error) = serde_json::from_slice(&reader.bytes) { if let Ok(error) = serde_json::from_slice(&reader.bytes) {
return Err(Error::Api(error)); return Err(Error::Api(error));
} }

Loading…
Cancel
Save