Error handling on API server

This commit is contained in:
Ara Sadoyan
2026-01-09 18:44:36 +01:00
parent 2d1a827007
commit 6c1d3c5ef8
8 changed files with 375 additions and 120 deletions

View File

@@ -21,6 +21,7 @@ impl BackgroundService for LB {
let tx_api = tx.clone();
let config = load_configuration(self.config.upstreams_conf.clone().as_str(), "filepath")
.await
.0
.expect("Failed to load configuration");
match config.typecfg.as_str() {

View File

@@ -92,11 +92,21 @@ async fn conf(State(mut st): State<AppState>, Query(params): Query<HashMap<Strin
if let Some(s) = params.get("key") {
if s.to_owned() == st.master_key {
if let Some(serverlist) = crate::utils::parceyaml::load_configuration(content.as_str(), "content").await {
st.config_sender.send(serverlist).await.unwrap();
return Response::builder().status(StatusCode::OK).body(Body::from("Config, conf file, updated !\n")).unwrap();
let sl = crate::utils::parceyaml::load_configuration(content.as_str(), "content").await;
if let Some(serverlist) = sl.0 {
let r = st.config_sender.send(serverlist).await;
match r {
Ok(_) => {
return Response::builder().status(StatusCode::OK).body(Body::from("Config, conf file, updated!\n")).unwrap();
}
Err(e) => {
let error_msg = format!("Failed to send configuration: {}\n", e);
return Response::builder().status(StatusCode::INTERNAL_SERVER_ERROR).body(Body::from(error_msg)).unwrap();
}
}
} else {
return Response::builder().status(StatusCode::BAD_GATEWAY).body(Body::from("Failed to parse config!\n")).unwrap();
let err: String = "Error parsing config file: ".to_owned() + sl.1.as_str() + "\n";
return Response::builder().status(StatusCode::BAD_GATEWAY).body(Body::from(err)).unwrap();
};
}
}