added should_err endpoint config option

This commit is contained in:
Edward Shen 2019-05-01 22:36:14 -04:00
parent 18a95cb3cd
commit 57574993b6
Signed by: edward
GPG key ID: F350507060ED6C90
3 changed files with 20 additions and 8 deletions

View file

@ -8,6 +8,7 @@ pub struct EndpointConfig {
pub code: Option<u16>,
pub body: Option<String>,
pub follow_redirects: Option<bool>,
pub should_err: Option<bool>,
}
#[derive(Deserialize, Serialize, Debug, Clone)]

View file

@ -33,7 +33,7 @@ pub type State = Arc<RwLock<QueryResults>>;
fn main() {
System::run(move || {
let config = from_str::<Config>(
&read_to_string("./endstat_conf.ron").expect("Could not find config file"),
&read_to_string("./endstat_conf.ron").expect("finding ./endstat_conf.ron"),
)
.unwrap();
let bind_addr = config.bind_address.clone();

View file

@ -3,7 +3,7 @@ use crate::{
handlers::{EndpointStatus, StatusGroup},
State,
};
use chrono::prelude::*;
use chrono::prelude::Utc;
use reqwest::{Client, RedirectPolicy, Url, UrlError};
use std::time::Duration;
@ -84,12 +84,23 @@ fn get_result(
error,
}
}
Err(e) => EndpointStatus {
status: 2,
location: url,
endpoint: label,
error: Some(format!("{}", e)),
},
Err(e) => {
if let Some(true) = endpoint.should_err {
EndpointStatus {
status: 0,
location: url,
endpoint: label,
error: None,
}
} else {
EndpointStatus {
status: 2,
location: url,
endpoint: label,
error: Some(format!("{}", e)),
}
}
}
}
}