made helper functions for EndpointStatus
This commit is contained in:
parent
57574993b6
commit
25ed4f0acb
2 changed files with 35 additions and 17 deletions
|
@ -15,6 +15,35 @@ pub struct EndpointStatus {
|
||||||
pub error: Option<String>,
|
pub error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl EndpointStatus {
|
||||||
|
pub fn ok(location: String, endpoint: String) -> Self {
|
||||||
|
EndpointStatus {
|
||||||
|
status: 0,
|
||||||
|
location,
|
||||||
|
endpoint,
|
||||||
|
error: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn warn(location: String, endpoint: String, error: Option<String>) -> Self {
|
||||||
|
EndpointStatus {
|
||||||
|
status: 1,
|
||||||
|
location,
|
||||||
|
endpoint,
|
||||||
|
error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn error(location: String, endpoint: String, error: Option<String>) -> Self {
|
||||||
|
EndpointStatus {
|
||||||
|
status: 2,
|
||||||
|
location,
|
||||||
|
endpoint,
|
||||||
|
error,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
pub struct StatusGroup {
|
pub struct StatusGroup {
|
||||||
pub label: String,
|
pub label: String,
|
||||||
|
|
|
@ -77,28 +77,17 @@ fn get_result(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
EndpointStatus {
|
if error.is_some() {
|
||||||
status: if error.is_some() { 1 } else { 0 },
|
EndpointStatus::warn(url, label, error)
|
||||||
location: url,
|
} else {
|
||||||
endpoint: label,
|
EndpointStatus::ok(url, label)
|
||||||
error,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if let Some(true) = endpoint.should_err {
|
if let Some(true) = endpoint.should_err {
|
||||||
EndpointStatus {
|
EndpointStatus::ok(url, label)
|
||||||
status: 0,
|
|
||||||
location: url,
|
|
||||||
endpoint: label,
|
|
||||||
error: None,
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
EndpointStatus {
|
EndpointStatus::error(url, label, Some(format!("{}", e)))
|
||||||
status: 2,
|
|
||||||
location: url,
|
|
||||||
endpoint: label,
|
|
||||||
error: Some(format!("{}", e)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue