#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct CustomResponse {
pub id: Option<i64>,
pub service: String,
pub namespace: String,
pub local_port: u16,
pub remote_port: u16,
pub context: String,
pub stdout: String,
pub stderr: String,
pub status: i32,
pub protocol: String,
}
impl CustomResponse {
pub fn failed(&self) -> bool {
self.status != 0
}
}
pub fn batch_failure(responses: &[CustomResponse]) -> Result<(), String> {
let failures: Vec<String> = responses
.iter()
.filter(|response| response.failed())
.map(|response| {
if response.stderr.trim().is_empty() {
match response.id {
Some(id) => format!("config {id} failed with no error message"),
None => "a configuration failed with no error message".to_owned(),
}
} else {
response.stderr.clone()
}
})
.collect();
if failures.is_empty() {
Ok(())
} else {
Err(failures.join("; "))
}
}