Skip to content

Commit

Permalink
error handling in Airlock
Browse files Browse the repository at this point in the history
  • Loading branch information
damoodamoo committed Sep 8, 2022
1 parent 9ab6315 commit c1859e1
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions ui/app/src/components/shared/airlock/AirlockViewRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { DefaultButton, Dialog, DialogFooter, IStackItemStyles, IStackStyles, MessageBar, MessageBarType, Panel, PanelType, Persona, PersonaSize, PrimaryButton, Spinner, SpinnerSize, Stack, TextField, useTheme } from "@fluentui/react";
import { DefaultButton, Dialog, DialogFooter, IStackItemStyles, IStackStyles, MessageBar, Panel, PanelType, Persona, PersonaSize, PrimaryButton, Spinner, SpinnerSize, Stack, TextField, useTheme } from "@fluentui/react";
import moment from "moment";
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
import { useNavigate, useParams } from "react-router-dom";
import { WorkspaceContext } from "../../../contexts/WorkspaceContext";
import { HttpMethod, useAuthApiCall } from "../../../hooks/useAuthApiCall";
import { AirlockRequest, AirlockRequestStatus } from "../../../models/airlock";
import { ApiEndpoint } from "../../../models/apiEndpoints";
import { APIError } from "../../../models/exceptions";
import { ExceptionLayout } from "../ExceptionLayout";

interface AirlockViewRequestProps {
requests: AirlockRequest[];
Expand Down Expand Up @@ -40,6 +42,9 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
const [hideCancelDialog, setHideCancelDialog] = useState(true);
const workspaceCtx = useContext(WorkspaceContext);
const apiCall = useAuthApiCall();
const [apiFilesLinkError, setApiFilesLinkError] = useState({} as APIError);
const [apiSubmitError, setApiSubmitError] = useState({} as APIError);
const [apiCancelError, setApiCancelError] = useState({} as APIError);
const navigate = useNavigate();
const theme = useTheme();

Expand Down Expand Up @@ -68,7 +73,9 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
workspaceCtx.workspaceApplicationIdURI
);
setFilesLink(linkObject.containerUrl);
} catch (error) {
} catch (err: any) {
err.userMessage = 'Error retrieving storage link';
setApiFilesLinkError(err);
setFilesLinkError(true);
}
}
Expand All @@ -89,7 +96,9 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
);
props.updateRequest(response.airlockRequest);
setHideSubmitDialog(true);
} catch (error) {
} catch (err: any) {
err.userMessage = 'Error submitting airlock request';
setApiSubmitError(err);
setSubmitError(true);
}
setSubmitting(false);
Expand All @@ -109,8 +118,11 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
);
props.updateRequest(response.airlockRequest);
setHideCancelDialog(true);
} catch (error) {
} catch (err: any) {
err.userMessage = 'Error cancelling airlock request';
setApiCancelError(err);
setCancelError(true);

}
setCancelling(false);
}
Expand All @@ -129,10 +141,10 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
}
<div style={{textAlign: 'end'}}>
{
request.status !== AirlockRequestStatus.Cancelled && <DefaultButton onClick={() => setHideCancelDialog(false)} styles={cancelButtonStyles}>Cancel Request</DefaultButton>
request.status !== AirlockRequestStatus.Cancelled && <DefaultButton onClick={() => {setCancelError(false); setHideCancelDialog(false)}} styles={cancelButtonStyles}>Cancel Request</DefaultButton>
}
{
request.status === AirlockRequestStatus.Draft && <PrimaryButton onClick={() => setHideSubmitDialog(false)}>Submit</PrimaryButton>
request.status === AirlockRequestStatus.Draft && <PrimaryButton onClick={() => {setSubmitError(false); setHideSubmitDialog(false)}}>Submit</PrimaryButton>
}
</div>
</>
Expand Down Expand Up @@ -236,14 +248,12 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
iconProps={{iconName: 'copy'}}
styles={{root: {minWidth: '40px'}}}
onClick={() => {navigator.clipboard.writeText(filesLink)}}
/> : <PrimaryButton onClick={generateFilesLink}>Generate</PrimaryButton>
/> : <PrimaryButton onClick={() => {setFilesLinkError(false); generateFilesLink()}}>Generate</PrimaryButton>
}
</Stack>
</Stack.Item>
{
filesLinkError && <MessageBar messageBarType={MessageBarType.error}>
Error retrieving storage link. Check console.
</MessageBar>
filesLinkError && <ExceptionLayout e={apiFilesLinkError} />
}
</Stack>
</>
Expand All @@ -260,7 +270,7 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
}}
>
{
submitError && <MessageBar messageBarType={MessageBarType.error}>Error submitting request. Check the console for details.</MessageBar>
submitError && <ExceptionLayout e={apiSubmitError} />
}
{
submitting
Expand All @@ -281,7 +291,7 @@ export const AirlockViewRequest: React.FunctionComponent<AirlockViewRequestProps
}}
>
{
cancelError && <MessageBar messageBarType={MessageBarType.error}>Error cancelling request. Check the console for details.</MessageBar>
cancelError && <ExceptionLayout e={apiCancelError} />
}
{
cancelling
Expand Down

0 comments on commit c1859e1

Please sign in to comment.