Skip to content

Commit

Permalink
refactor: return 500 Internal Server Error instead of 200 OK if any e…
Browse files Browse the repository at this point in the history
…rror occurred
  • Loading branch information
knsd committed Jun 14, 2018
1 parent afaf65c commit a170d30
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde_urlencoded;
use tacho;

use metrics::{METRICS, REPORTER};
use pinger::Pinger;
use pinger::{Pinger, Error as PingerError};
use settings::Settings;
use utils::{Protocol, NameOrIpAddr, boxed};

Expand Down Expand Up @@ -175,7 +175,13 @@ fn ping(request: PingRequest, settings: Settings, pinger: Pinger) -> impl Future

let future = pinger.ping(name.clone(), protocol, count, resolve_timeout, ping_timeout);
let future = future.map_err(|error| {
(StatusCode::OK, Body::from(format!("{}", error)))
let body = Body::from(match error {
PingerError::ResolveError {..} => "Unable to resolve",
PingerError::ResolveTimeoutError {..} => "Resolve timeout",
PingerError::PingError {..} => "Internal error",
});
(StatusCode::INTERNAL_SERVER_ERROR, body)

});

let future = future.and_then(move |(resolve_time_ns, ip, pings)| {
Expand Down

0 comments on commit a170d30

Please sign in to comment.