Improve errors reporting
This commit is contained in:
@ -14,11 +14,21 @@ pub async fn create(client: LibVirtReq, req: web::Json<NetworkInfo>) -> HttpResu
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
log::error!("Failed to extract network info! {e}");
|
||||
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
||||
return Ok(
|
||||
HttpResponse::BadRequest().json(format!("Failed to extract network info! {e}"))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
let uid = client.update_network(network).await?;
|
||||
let uid = match client.update_network(network).await {
|
||||
Ok(u) => u,
|
||||
Err(e) => {
|
||||
log::error!("Failed to update network! {e}");
|
||||
return Ok(
|
||||
HttpResponse::InternalServerError().json(format!("Failed to update network! {e}"))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Ok(HttpResponse::Ok().json(NetworkID { uid }))
|
||||
}
|
||||
@ -56,7 +66,13 @@ pub async fn update(
|
||||
) -> HttpResult {
|
||||
let mut network = body.0.to_virt_network()?;
|
||||
network.uuid = Some(path.uid);
|
||||
client.update_network(network).await?;
|
||||
|
||||
if let Err(e) = client.update_network(network).await {
|
||||
log::error!("Failed to update network! {e}");
|
||||
return Ok(
|
||||
HttpResponse::InternalServerError().json(format!("Failed to update network!\n${e}"))
|
||||
);
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json("Network updated"))
|
||||
}
|
||||
@ -115,9 +131,13 @@ pub async fn status(client: LibVirtReq, id: web::Path<NetworkID>) -> HttpResult
|
||||
|
||||
/// Start a network
|
||||
pub async fn start(client: LibVirtReq, id: web::Path<NetworkID>) -> HttpResult {
|
||||
client.start_network(id.uid).await?;
|
||||
|
||||
Ok(HttpResponse::Accepted().json("Network started"))
|
||||
match client.start_network(id.uid).await {
|
||||
Ok(_) => Ok(HttpResponse::Accepted().json("Network started")),
|
||||
Err(e) => {
|
||||
log::error!("Failed to start a network! {e}: {:?}", id.uid);
|
||||
Ok(HttpResponse::InternalServerError().json(format!("Failed to start network! {e}")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop a network
|
||||
|
Reference in New Issue
Block a user