From ee5678831f64c120438749c58ac3a3afc455d47a Mon Sep 17 00:00:00 2001 From: HuaizhiDai Date: Wed, 12 Feb 2025 16:40:11 +1100 Subject: [PATCH 1/3] add timeout check --- .../subpages/side-cards/DownloadDialog.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx b/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx index 8907b189..dcf04cb7 100644 --- a/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx +++ b/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useMemo, useState } from "react"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; import { Box, Button, @@ -40,6 +40,18 @@ const DownloadDialog: React.FC = ({ open, setOpen }) => { const [isProcessing, setIsProcessing] = useState(false); const [processingStatus, setProcessingStatus] = useState(""); + // if a request is processing too long, we assume it is failed + useEffect(() => { + if (isProcessing) { + const timer = setTimeout(() => { + console.log("Processing time out."); + setProcessingStatus("408"); + setIsProcessing(false); + }, 8000); + return () => clearTimeout(timer); + } + }, [isProcessing]); + const bboxConditions = useMemo( () => downloadConditions.filter( @@ -74,6 +86,9 @@ const DownloadDialog: React.FC = ({ open, setOpen }) => { if (/^2\d{2}$/.test(processingStatus)) { return "Succeeded! An email will be sent to you shortly"; } + if (processingStatus === "408") { + return "Request timeout! Please try again later"; + } if (/^4\d{2}$/.test(processingStatus)) { return "Failed! Please try again later"; } @@ -101,7 +116,6 @@ const DownloadDialog: React.FC = ({ open, setOpen }) => { .then((response) => { setProcessingStatus(response.status.message); setIsProcessing(false); - return response; }); }, [dateRange.end, dateRange.start, dispatch, location.search, multiPolygon] From e446f85b7775c73c45a562afea4e37696f406e2e Mon Sep 17 00:00:00 2001 From: HuaizhiDai Date: Wed, 12 Feb 2025 16:48:33 +1100 Subject: [PATCH 2/3] add timeout check --- src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx b/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx index dcf04cb7..e7ae8201 100644 --- a/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx +++ b/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx @@ -101,6 +101,10 @@ const DownloadDialog: React.FC = ({ open, setOpen }) => { if (!uuid) { return; } + + // make sure the email is not capital-sensitive + email = email.toLowerCase(); + const request: DatasetDownloadRequest = { inputs: { uuid: uuid, From c524971bd398b51ff13c803ce8e27a9f5d6dfd21 Mon Sep 17 00:00:00 2001 From: HuaizhiDai Date: Wed, 12 Feb 2025 16:54:26 +1100 Subject: [PATCH 3/3] make code more readable --- src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx b/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx index e7ae8201..7e685182 100644 --- a/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx +++ b/src/pages/detail-page/subpages/side-cards/DownloadDialog.tsx @@ -33,6 +33,8 @@ interface DownloadDialogProps { setOpen: (open: boolean) => void; } +const TIMEOUT_LIMIT = 8000; + const DownloadDialog: React.FC = ({ open, setOpen }) => { const location = useLocation(); const dispatch = useAppDispatch(); @@ -47,7 +49,7 @@ const DownloadDialog: React.FC = ({ open, setOpen }) => { console.log("Processing time out."); setProcessingStatus("408"); setIsProcessing(false); - }, 8000); + }, TIMEOUT_LIMIT); return () => clearTimeout(timer); } }, [isProcessing]);