diff --git a/src/frontend/src/constants/constants.ts b/src/frontend/src/constants/constants.ts index cfe5f46a3..7ec483bec 100644 --- a/src/frontend/src/constants/constants.ts +++ b/src/frontend/src/constants/constants.ts @@ -1068,3 +1068,5 @@ export const OPENAI_VOICES = [ export const DEFAULT_POLLING_INTERVAL = 5000; export const DEFAULT_TIMEOUT = 30000; export const DEFAULT_FILE_PICKER_TIMEOUT = 60000; + +export const UUID_PARSING_ERROR = "uuid_parsing"; diff --git a/src/frontend/src/hooks/flows/use-add-flow.ts b/src/frontend/src/hooks/flows/use-add-flow.ts index 3fbbcb32a..23c229b25 100644 --- a/src/frontend/src/hooks/flows/use-add-flow.ts +++ b/src/frontend/src/hooks/flows/use-add-flow.ts @@ -1,3 +1,4 @@ +import { UUID_PARSING_ERROR } from "@/constants/constants"; import { usePostAddFlow } from "@/controllers/API/queries/flows/use-post-add-flow"; import useAlertStore from "@/stores/alertStore"; import useFlowsManagerStore from "@/stores/flowsManagerStore"; @@ -17,15 +18,19 @@ import { cloneDeep } from "lodash"; import { useParams } from "react-router-dom"; import useDeleteFlow from "./use-delete-flow"; +const FLOW_CREATION_ERROR = "Flow creation error"; +const FOLDER_NOT_FOUND_ERROR = "Folder not found. Redirecting to flows..."; +const FLOW_CREATION_ERROR_MESSAGE = + "An unexpected error occurred, please try again"; +const REDIRECT_DELAY = 3000; const useAddFlow = () => { const flows = useFlowsManagerStore((state) => state.flows); const setFlows = useFlowsManagerStore((state) => state.setFlows); const { deleteFlow } = useDeleteFlow(); const { setFlowToCanvas } = useFlowsManagerStore(); - + const setNoticeData = useAlertStore.getState().setNoticeData; const { folderId } = useParams(); - const myCollectionId = useFolderStore((state) => state.myCollectionId); const unavailableFields = useGlobalVariablesStore( @@ -92,18 +97,26 @@ const useAddFlow = () => { resolve(createdFlow.id); }, onError: (error) => { + if (error?.response?.data?.detail[0]?.type === UUID_PARSING_ERROR) { + setNoticeData({ + title: FOLDER_NOT_FOUND_ERROR, + }); + setTimeout(() => { + window.location.href = `/flows`; + }, REDIRECT_DELAY); + + return; + } + if (error.response?.data?.detail) { useAlertStore.getState().setErrorData({ - title: "Could not create flow", + title: FLOW_CREATION_ERROR, list: [error.response?.data?.detail], }); } else { useAlertStore.getState().setErrorData({ - title: "Could not create flow", - list: [ - error.message ?? - "An unexpected error occurred, please try again", - ], + title: FLOW_CREATION_ERROR, + list: [error.message ?? FLOW_CREATION_ERROR_MESSAGE], }); } reject(error); // Re-throw the error so the caller can handle it if needed},