Improve errors reporting
This commit is contained in:
parent
2a52b5c035
commit
bc15846b67
@ -14,11 +14,21 @@ pub async fn create(client: LibVirtReq, req: web::Json<NetworkInfo>) -> HttpResu
|
|||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to extract network info! {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 }))
|
Ok(HttpResponse::Ok().json(NetworkID { uid }))
|
||||||
}
|
}
|
||||||
@ -56,7 +66,13 @@ pub async fn update(
|
|||||||
) -> HttpResult {
|
) -> HttpResult {
|
||||||
let mut network = body.0.to_virt_network()?;
|
let mut network = body.0.to_virt_network()?;
|
||||||
network.uuid = Some(path.uid);
|
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"))
|
Ok(HttpResponse::Ok().json("Network updated"))
|
||||||
}
|
}
|
||||||
@ -115,9 +131,13 @@ pub async fn status(client: LibVirtReq, id: web::Path<NetworkID>) -> HttpResult
|
|||||||
|
|
||||||
/// Start a network
|
/// Start a network
|
||||||
pub async fn start(client: LibVirtReq, id: web::Path<NetworkID>) -> HttpResult {
|
pub async fn start(client: LibVirtReq, id: web::Path<NetworkID>) -> HttpResult {
|
||||||
client.start_network(id.uid).await?;
|
match client.start_network(id.uid).await {
|
||||||
|
Ok(_) => Ok(HttpResponse::Accepted().json("Network started")),
|
||||||
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
|
/// Stop a network
|
||||||
|
@ -24,10 +24,20 @@ pub async fn create(client: LibVirtReq, req: web::Json<VMInfo>) -> HttpResult {
|
|||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to extract domain info! {e}");
|
log::error!("Failed to extract domain info! {e}");
|
||||||
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
return Ok(
|
||||||
|
HttpResponse::BadRequest().json(format!("Failed to extract domain info!\n{e}"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let id = match client.update_domain(domain).await {
|
||||||
|
Ok(i) => i,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Failed to update domain info! {e}");
|
||||||
|
return Ok(
|
||||||
|
HttpResponse::InternalServerError().json(format!("Failed to create domain!\n{e}"))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let id = client.update_domain(domain).await?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(VMUuid { uuid: id }))
|
Ok(HttpResponse::Ok().json(VMUuid { uuid: id }))
|
||||||
}
|
}
|
||||||
@ -96,11 +106,14 @@ pub async fn update(
|
|||||||
) -> HttpResult {
|
) -> HttpResult {
|
||||||
let mut domain = req.0.to_domain().map_err(|e| {
|
let mut domain = req.0.to_domain().map_err(|e| {
|
||||||
log::error!("Failed to extract domain info! {e}");
|
log::error!("Failed to extract domain info! {e}");
|
||||||
HttpResponse::BadRequest().body(e.to_string())
|
HttpResponse::BadRequest().json(format!("Failed to extract domain info! {e}"))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
domain.uuid = Some(id.uid);
|
domain.uuid = Some(id.uid);
|
||||||
client.update_domain(domain).await?;
|
if let Err(e) = client.update_domain(domain).await {
|
||||||
|
log::error!("Failed to update domain info! {e}");
|
||||||
|
return Ok(HttpResponse::BadRequest().json(format!("Failed to update domain info!\n{e}")));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
}
|
}
|
||||||
@ -159,7 +172,7 @@ pub async fn start(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpRe
|
|||||||
Ok(_) => HttpResponse::Ok().json("Domain started"),
|
Ok(_) => HttpResponse::Ok().json("Domain started"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to start domain {:?} ! {e}", id.uid);
|
log::error!("Failed to start domain {:?} ! {e}", id.uid);
|
||||||
HttpResponse::InternalServerError().json("Failed to start domain!")
|
HttpResponse::InternalServerError().json(format!("Failed to start domain! - {e}"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import { BaseLoginPage } from "./widgets/BaseLoginPage";
|
|||||||
import { ViewNetworkRoute } from "./routes/ViewNetworkRoute";
|
import { ViewNetworkRoute } from "./routes/ViewNetworkRoute";
|
||||||
import { VMXMLRoute } from "./routes/VMXMLRoute";
|
import { VMXMLRoute } from "./routes/VMXMLRoute";
|
||||||
import { NetXMLRoute } from "./routes/NetXMLRoute";
|
import { NetXMLRoute } from "./routes/NetXMLRoute";
|
||||||
|
import { HomeRoute } from "./routes/HomeRoute";
|
||||||
|
|
||||||
interface AuthContext {
|
interface AuthContext {
|
||||||
signedIn: boolean;
|
signedIn: boolean;
|
||||||
@ -47,6 +48,8 @@ export function App() {
|
|||||||
createRoutesFromElements(
|
createRoutesFromElements(
|
||||||
signedIn || ServerApi.Config.auth_disabled ? (
|
signedIn || ServerApi.Config.auth_disabled ? (
|
||||||
<Route path="*" element={<BaseAuthenticatedPage />}>
|
<Route path="*" element={<BaseAuthenticatedPage />}>
|
||||||
|
<Route path="" element={<HomeRoute />} />
|
||||||
|
|
||||||
<Route path="iso" element={<IsoFilesRoute />} />
|
<Route path="iso" element={<IsoFilesRoute />} />
|
||||||
|
|
||||||
<Route path="vms" element={<VMListRoute />} />
|
<Route path="vms" element={<VMListRoute />} />
|
||||||
|
@ -17,7 +17,7 @@ interface APIResponse {
|
|||||||
|
|
||||||
export class ApiError extends Error {
|
export class ApiError extends Error {
|
||||||
constructor(message: string, public code: number, public data: any) {
|
constructor(message: string, public code: number, public data: any) {
|
||||||
super(message);
|
super(`HTTP status: ${code}\nMessage: ${message}\nData=${data}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,10 @@ export function AlertDialogProvider(p: PropsWithChildren): React.ReactElement {
|
|||||||
>
|
>
|
||||||
{title && <DialogTitle id="alert-dialog-title">{title}</DialogTitle>}
|
{title && <DialogTitle id="alert-dialog-title">{title}</DialogTitle>}
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContentText id="alert-dialog-description">
|
<DialogContentText
|
||||||
|
id="alert-dialog-description"
|
||||||
|
style={{ whiteSpace: "pre" }}
|
||||||
|
>
|
||||||
{message}
|
{message}
|
||||||
</DialogContentText>
|
</DialogContentText>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
@ -25,7 +25,7 @@ export function CreateNetworkRoute(): React.ReactElement {
|
|||||||
navigate(`/net/${res.uid}`);
|
navigate(`/net/${res.uid}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert("Failed to create network!");
|
alert(`Failed to create network!\n${e}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ export function EditNetworkRoute(): React.ReactElement {
|
|||||||
navigate(NetworkURL(network!));
|
navigate(NetworkURL(network!));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert("Failed to update network!");
|
alert(`Failed to update network!\n${e}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ export function CreateVMRoute(): React.ReactElement {
|
|||||||
navigate(v.ViewURL);
|
navigate(v.ViewURL);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
alert("Failed to create VM!");
|
alert(`Failed to create VM!\n${e}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
13
virtweb_frontend/src/routes/HomeRoute.tsx
Normal file
13
virtweb_frontend/src/routes/HomeRoute.tsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
|
||||||
|
|
||||||
|
export function HomeRoute(): React.ReactElement {
|
||||||
|
return (
|
||||||
|
<VirtWebRouteContainer label="VirtWeb">
|
||||||
|
<p>VirtWeb is an Open Source web ui for Libvirt.</p>
|
||||||
|
<p>
|
||||||
|
You can use the menu on the left to access the different sections of the
|
||||||
|
application.
|
||||||
|
</p>
|
||||||
|
</VirtWebRouteContainer>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user