Skip to content
Snippets Groups Projects
Commit fd990eb1 authored by Max Frederiksen's avatar Max Frederiksen
Browse files

Merge branch 'CE-3015-error-message-503' into 'develop'

CE-3015: Implement correct error handling for operation errors

See merge request !533
parents 26bb2114 2890126c
No related branches found
No related tags found
3 merge requests!542Prepare 4.1.0,!540Sync,!533CE-3015: Implement correct error handling for operation errors
Pipeline #197562 passed
...@@ -3,6 +3,7 @@ import { Navigate } from "react-router-dom"; ...@@ -3,6 +3,7 @@ import { Navigate } from "react-router-dom";
import { IOCDeployDialog } from "../IOCDeployDialog"; import { IOCDeployDialog } from "../IOCDeployDialog";
import { apiContext } from "../../../api/DeployApi"; import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common"; import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { getErrorMessage } from "../../common/Helper";
// Process component // Process component
export function DeployIOC({ export function DeployIOC({
...@@ -29,11 +30,7 @@ export function DeployIOC({ ...@@ -29,11 +30,7 @@ export function DeployIOC({
useEffect(() => { useEffect(() => {
if (deployError) { if (deployError) {
setButtonDisabled(false); setButtonDisabled(false);
setError( setError(getErrorMessage(deployError));
deployError?.response?.body?.description ??
deployError?.message ??
"An unknown error occurred"
);
} }
}, [deployError, setButtonDisabled]); }, [deployError, setButtonDisabled]);
......
...@@ -77,6 +77,7 @@ export function IOCDeployDialog({ ...@@ -77,6 +77,7 @@ export function IOCDeployDialog({
const handleClose = () => { const handleClose = () => {
setOpen(false); setOpen(false);
resetError();
}; };
useEffect(() => { useEffect(() => {
......
...@@ -5,13 +5,14 @@ import { ...@@ -5,13 +5,14 @@ import {
Typography, Typography,
Tooltip Tooltip
} from "@mui/material"; } from "@mui/material";
import { useState, useEffect, useContext, useCallback } from "react"; import { useState, useEffect, useCallback } from "react";
import { ConfirmationDialog, useAPIMethod } from "@ess-ics/ce-ui-common"; import { ConfirmationDialog } from "@ess-ics/ce-ui-common";
import Alert from "@mui/material/Alert"; import Alert from "@mui/material/Alert";
import { initRequestParams } from "../../common/Helper"; import { initRequestParams } from "../../common/Helper";
import AccessControl from "../../auth/AccessControl"; import AccessControl from "../../auth/AccessControl";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { apiContext } from "../../../api/DeployApi"; import { useStartOperationMutation } from "../../../store/deployApi";
import { getErrorMessage } from "../../common/Alerts/ApiAlertError";
export function IOCService({ export function IOCService({
ioc, ioc,
...@@ -21,52 +22,28 @@ export function IOCService({ ...@@ -21,52 +22,28 @@ export function IOCService({
setButtonDisabled, setButtonDisabled,
jobLazyParams jobLazyParams
}) { }) {
const [error, setError] = useState();
const navigate = useNavigate(); const navigate = useNavigate();
const [error, setError] = useState();
const [inProgress, setInProgress] = useState(false); const [inProgress, setInProgress] = useState(false);
const [startModalOpen, setStartModalOpen] = useState(false); const [startModalOpen, setStartModalOpen] = useState(false);
const [stopModalOpen, setStopModalOpen] = useState(false); const [stopModalOpen, setStopModalOpen] = useState(false);
const [command, setCommand] = useState(null); const [command, setCommand] = useState(null);
const client = useContext(apiContext); const [startOperation, { error: jobError, data: jobData }] =
useStartOperationMutation();
const {
value: startJob,
wrapper: startIOC,
error: startJobError
} = useAPIMethod({
fcn: client.apis.IOCs.startOperation,
call: false
});
const {
value: stopJob,
wrapper: stopIOC,
error: stopJobError
} = useAPIMethod({
fcn: client.apis.IOCs.startOperation,
call: false
});
useEffect(() => { useEffect(() => {
setError(startJobError?.message); setError(jobError);
}, [startJobError]); }, [jobError]);
useEffect(() => { useEffect(() => {
setError(stopJobError?.message); if (jobData && (!command || command.id !== jobData.id)) {
}, [stopJobError]); navigate(`/jobs/${jobData.id}`);
setCommand(jobData);
useEffect(() => {
if (startJob && (!command || command.id !== startJob.id)) {
navigate(`/jobs/${startJob.id}`);
setCommand(startJob);
} else if (stopJob && (!command || command.id !== stopJob.id)) {
navigate(`/jobs/${stopJob.id}`);
setCommand(stopJob);
} else if (currentCommand) { } else if (currentCommand) {
setCommand(currentCommand); setCommand(currentCommand);
} }
}, [startJob, stopJob, command, currentCommand, navigate]); }, [jobData, command, currentCommand, navigate]);
const resetUI = useCallback(() => { const resetUI = useCallback(() => {
setCommand(null); setCommand(null);
...@@ -78,16 +55,12 @@ export function IOCService({ ...@@ -78,16 +55,12 @@ export function IOCService({
setInProgress(true); setInProgress(true);
setButtonDisabled(true); setButtonDisabled(true);
startIOC( startOperation({
{ iocId: ioc.id,
ioc_id: ioc.id createJobRequest: {
}, type: "START"
{
requestBody: {
type: "START"
}
} }
); });
let requestParams = initRequestParams(jobLazyParams); let requestParams = initRequestParams(jobLazyParams);
...@@ -99,7 +72,7 @@ export function IOCService({ ...@@ -99,7 +72,7 @@ export function IOCService({
jobLazyParams, jobLazyParams,
resetUI, resetUI,
setButtonDisabled, setButtonDisabled,
startIOC startOperation
]); ]);
const stop = useCallback(() => { const stop = useCallback(() => {
...@@ -107,16 +80,12 @@ export function IOCService({ ...@@ -107,16 +80,12 @@ export function IOCService({
setInProgress(true); setInProgress(true);
setButtonDisabled(true); setButtonDisabled(true);
stopIOC( startOperation({
{ iocId: ioc.id,
ioc_id: ioc.id createJobRequest: {
}, type: "STOP"
{
requestBody: {
type: "STOP"
}
} }
); });
let requestParams = initRequestParams(jobLazyParams); let requestParams = initRequestParams(jobLazyParams);
...@@ -128,7 +97,7 @@ export function IOCService({ ...@@ -128,7 +97,7 @@ export function IOCService({
jobLazyParams, jobLazyParams,
resetUI, resetUI,
setButtonDisabled, setButtonDisabled,
stopIOC startOperation
]); ]);
const onStartModalClose = useCallback(() => { const onStartModalClose = useCallback(() => {
...@@ -264,7 +233,7 @@ export function IOCService({ ...@@ -264,7 +233,7 @@ export function IOCService({
md={12} md={12}
> >
{error ? ( {error ? (
<Alert severity="error">{error}</Alert> <Alert severity="error">{getErrorMessage(error)}</Alert>
) : ( ) : (
inProgress && <LinearProgress color="primary" /> inProgress && <LinearProgress color="primary" />
)} )}
......
import { Stack, Typography } from "@mui/material"; import { Stack, Typography, Button } from "@mui/material";
import Alert from "@mui/material/Alert"; import Alert from "@mui/material/Alert";
import { ConfirmationDialog } from "@ess-ics/ce-ui-common"; import { Dialog } from "@ess-ics/ce-ui-common";
export function IOCUndeployDialog({ export function IOCUndeployDialog({
open, open,
...@@ -8,22 +8,19 @@ export function IOCUndeployDialog({ ...@@ -8,22 +8,19 @@ export function IOCUndeployDialog({
submitCallback, submitCallback,
ioc, ioc,
error, error,
resetError,
buttonDisabled,
setButtonDisabled setButtonDisabled
}) { }) {
const handleClose = () => { const handleClose = () => {
setOpen(false); setOpen(false);
resetError();
}; };
const onSubmit = (event) => { const onSubmit = (event) => {
event.preventDefault(); event.preventDefault();
setButtonDisabled(true); setButtonDisabled(true);
submitCallback({
ioc_id: ioc.id
});
};
const onConfirm = () => {
submitCallback( submitCallback(
{ {
ioc_id: ioc.id ioc_id: ioc.id
...@@ -37,7 +34,7 @@ export function IOCUndeployDialog({ ...@@ -37,7 +34,7 @@ export function IOCUndeployDialog({
}; };
return ( return (
<ConfirmationDialog <Dialog
open={open} open={open}
onClose={handleClose} onClose={handleClose}
title={ title={
...@@ -48,9 +45,6 @@ export function IOCUndeployDialog({ ...@@ -48,9 +45,6 @@ export function IOCUndeployDialog({
Undeploy Undeploy
</Typography> </Typography>
} }
confirmText="Undeploy"
cancelText="Cancel"
onConfirm={onConfirm}
content={ content={
<Stack <Stack
component="form" component="form"
...@@ -69,6 +63,27 @@ export function IOCUndeployDialog({ ...@@ -69,6 +63,27 @@ export function IOCUndeployDialog({
{ioc?.activeDeployment?.host?.fqdn}? {ioc?.activeDeployment?.host?.fqdn}?
</Typography> </Typography>
{error ? <Alert severity="error">{error}</Alert> : <></>} {error ? <Alert severity="error">{error}</Alert> : <></>}
<Stack
flexDirection="row"
justifyContent="flex-end"
gap={2}
marginTop={1}
>
<Button
onClick={handleClose}
color="primary"
>
Cancel
</Button>
<Button
color="primary"
variant="contained"
type="submit"
disabled={!ioc || error || buttonDisabled}
>
Undeploy
</Button>
</Stack>
</Stack> </Stack>
} }
/> />
......
...@@ -3,6 +3,7 @@ import { Navigate } from "react-router-dom"; ...@@ -3,6 +3,7 @@ import { Navigate } from "react-router-dom";
import { IOCUndeployDialog } from "../IOCUndeployDialog"; import { IOCUndeployDialog } from "../IOCUndeployDialog";
import { apiContext } from "../../../api/DeployApi"; import { apiContext } from "../../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common"; import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { getErrorMessage } from "../../common/Helper";
// Process component // Process component
export function UndeployIOC({ export function UndeployIOC({
...@@ -27,7 +28,7 @@ export function UndeployIOC({ ...@@ -27,7 +28,7 @@ export function UndeployIOC({
useEffect(() => { useEffect(() => {
if (deploymentError) { if (deploymentError) {
setButtonDisabled(false); setButtonDisabled(false);
setError(deploymentError?.message); setError(getErrorMessage(deploymentError));
} }
}, [deploymentError, setButtonDisabled]); }, [deploymentError, setButtonDisabled]);
...@@ -39,6 +40,7 @@ export function UndeployIOC({ ...@@ -39,6 +40,7 @@ export function UndeployIOC({
submitCallback={action} submitCallback={action}
ioc={ioc} ioc={ioc}
error={error} error={error}
resetError={() => setError(null)}
buttonDisabled={buttonDisabled} buttonDisabled={buttonDisabled}
setButtonDisabled={setButtonDisabled} setButtonDisabled={setButtonDisabled}
/> />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment