fix: Enhance error handling with new constants in flow management components (devx) (#7562)
* 📝 (constants.ts): add UUID_PARSING_ERROR constant for better error handling in use-add-flow.ts 🐛 (use-add-flow.ts): handle UUID_PARSING_ERROR in onError callback to display a specific error message and redirect to flows page if UUID parsing error occurs * ✨ (use-add-flow.ts): introduce constant REDIRECT_DELAY to improve code readability and maintainability
This commit is contained in:
parent
f14811fc8d
commit
e30b1985d1
2 changed files with 23 additions and 8 deletions
|
|
@ -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";
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue