Skip to content

Commit

Permalink
feat: Improve error handling for folder downloads in the Cart
Browse files Browse the repository at this point in the history
  • Loading branch information
PintoGideon committed May 10, 2024
1 parent e049f4c commit 0c1905a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
50 changes: 36 additions & 14 deletions src/components/NewLibrary/Cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
FileBrowserFolder,
Feed,
} from "@fnndsc/chrisapi";
import { Button, Grid, GridItem, Tooltip } from "@patternfly/react-core";
import { Button, Grid, GridItem, Tooltip, Text } from "@patternfly/react-core";
import { Drawer, List } from "antd";
import { useContext } from "react";
import { DotsIndicator } from "../Common";
Expand Down Expand Up @@ -71,6 +71,8 @@ export const Status = ({ item }: { item: SelectionPayload }) => {
variant="plain"
icon={<CheckCircleIcon color="#3E8635" width="2em" height="2em" />}
/>
) : currentStatus === FolderDownloadTypes.cancelled ? (
<Text>Cancelled</Text>
) : currentStatus ? (
<DotsIndicator title={folderStatusMap[currentStatus]} />
) : null}
Expand Down Expand Up @@ -121,18 +123,32 @@ const Cart = ({
FolderDownloadTypes.started,
),
);
try {
const path = payload.data.path;
const cannotDownload = [
"home",
`home/${username}`,
`home/${username}/uploads`,
"SERVICES",
];

if (cannotDownload.includes(path)) {
throw new Error(
`Please avoid zipping folders listed here: ${cannotDownload.join(
", ",
)}`,
);
}

const path = payload.data.path;
const client = ChrisAPIClient.getClient();
const client = ChrisAPIClient.getClient();

dispatch(
downloadFolderStatus(
payload as FileBrowserFolder,
FolderDownloadTypes.creatingFeed,
),
);
dispatch(
downloadFolderStatus(
payload as FileBrowserFolder,
FolderDownloadTypes.creatingFeed,
),
);

try {
const dircopy = await getPlugin("pl-dircopy");

if (!dircopy) {
Expand Down Expand Up @@ -173,9 +189,9 @@ const Cart = ({
name: "zip v20240311",
});

if (!pipelineList) {
if (!pipelineList.data) {
throw new Error(
"Is the zip pipeline registered with the name zip v20240311",
"Is the zip pipeline registered with the name zip v20240311?",
);
}

Expand Down Expand Up @@ -239,7 +255,13 @@ const Cart = ({
}
}
} catch (e) {
// biome-ignore lint/complexity/noUselessCatch: <explanation>
console.log("ERROR");
dispatch(
downloadFolderStatus(
payload as FileBrowserFolder,
FolderDownloadTypes.cancelled,
),
);
throw e;
}
}
Expand Down Expand Up @@ -333,7 +355,7 @@ const Cart = ({
);
}}
/>
{isError && <Alert type="error" description={error.message} />}
{isError && <Alert type="error" closable description={error.message} />}
</Drawer>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/NewLibrary/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export enum DownloadTypes {
started = "STARTED",
progress = "PROGRESS",
finished = "FINISHED",
cancelled = "CANCELLED",
}

export enum FolderDownloadTypes {
Expand All @@ -61,6 +62,7 @@ export enum FolderDownloadTypes {
zippingFolder = "ZIPPING_FOLDER",
startingDownload = "STARTING_DOWNLOAD",
finished = "FINISHED",
cancelled = "CANCELLED",
}

export type LibraryPayload = {
Expand Down

0 comments on commit 0c1905a

Please sign in to comment.