From 206407c1337c640ed33662eeb2bd90bcee9bc312 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 4 Sep 2020 19:06:14 -0400 Subject: [PATCH] still trying to get retry to work (broken) --- src/main.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index e3bf81e..813a30d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -144,6 +144,7 @@ fn speak_proxy( transaction: MaybeNewRelicTransaction, endpoint: &'static str) -> BoxFut { + info!("speak_proxy()"); let mut headers = req.headers().clone(); // This is the IP of the Digital Ocean load balancer. @@ -170,15 +171,22 @@ fn speak_proxy( let client = Client::new(); let fut = client - //.get(Uri::from_static("http://httpbin.org/ip")) - .get(Uri::from_static("http://asdfahsfahshfajshdfasf.com/ip")) - .and_then(|res| { - info!("status: {}", res.status()); - // Concatenate the body stream into a single buffer... - // This returns a new future, since we must stream body. - res.into_body().concat2() + //.get(Uri::from_cstatic("http://httpbin.org/ip")) + .get(Uri::from_static("http://brand.io/404notexit")) + .then(|res| { + let body = res.into_body(); + let status_code = res.status(); + + let inner = body.concat2(); + if status_code.is_success() { + // Concatenate the body stream into a single buffer... + // This returns a new future, since we must stream body. + future::err(inner) + } else { + future::ok(inner) + } }) - .and_then(|body| { + .then(|body| { // The body is just bytes, but let's print a string... let s = ::std::str::from_utf8(&body) .expect("httpbin sends utf-8 JSON") @@ -192,7 +200,6 @@ fn speak_proxy( // out that Result is a Future that is ready immediately. Ok(r) }) - .or_else(|err| { println!("error: {}", err); let b = Body::from("test".to_string());