From f651c756b612e69032b0e754055ba01efbe22a0d Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 12 Dec 2023 13:30:59 +0100 Subject: [PATCH] Improve errors reporting --- .../src/controllers/network_controller.rs | 13 ++++++++++--- virtweb_backend/src/controllers/vm_controller.rs | 9 ++++++++- .../src/hooks/providers/AlertDialogProvider.tsx | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/virtweb_backend/src/controllers/network_controller.rs b/virtweb_backend/src/controllers/network_controller.rs index 246d9e6..562fc40 100644 --- a/virtweb_backend/src/controllers/network_controller.rs +++ b/virtweb_backend/src/controllers/network_controller.rs @@ -35,9 +35,16 @@ pub async fn create(client: LibVirtReq, req: web::Json) -> HttpResu /// Get the list of networks pub async fn list(client: LibVirtReq) -> HttpResult { - let networks = client - .get_full_networks_list() - .await? + let networks = match client.get_full_networks_list().await { + Err(e) => { + log::error!("Failed to get the list of networks! {e}"); + return Ok(HttpResponse::InternalServerError() + .json(format!("Failed to get the list of networks! {e}"))); + } + Ok(l) => l, + }; + + let networks = networks .into_iter() .map(|n| NetworkInfo::from_xml(n).unwrap()) .collect::>(); diff --git a/virtweb_backend/src/controllers/vm_controller.rs b/virtweb_backend/src/controllers/vm_controller.rs index 490b389..d169cb4 100644 --- a/virtweb_backend/src/controllers/vm_controller.rs +++ b/virtweb_backend/src/controllers/vm_controller.rs @@ -44,7 +44,14 @@ pub async fn create(client: LibVirtReq, req: web::Json) -> HttpResult { /// Get the list of domains pub async fn list_all(client: LibVirtReq) -> HttpResult { - let list = client.get_full_domains_list().await?; + let list = match client.get_full_domains_list().await { + Err(e) => { + log::error!("Failed to get the list of domains! {e}"); + return Ok(HttpResponse::InternalServerError() + .json(format!("Failed to get the list of domains! {e}"))); + } + Ok(l) => l, + }; let mut out = Vec::with_capacity(list.len()); for entry in list { diff --git a/virtweb_frontend/src/hooks/providers/AlertDialogProvider.tsx b/virtweb_frontend/src/hooks/providers/AlertDialogProvider.tsx index ec6a756..520e56e 100644 --- a/virtweb_frontend/src/hooks/providers/AlertDialogProvider.tsx +++ b/virtweb_frontend/src/hooks/providers/AlertDialogProvider.tsx @@ -51,7 +51,7 @@ export function AlertDialogProvider(p: PropsWithChildren): React.ReactElement { {message}