From 96dfedde6e4a9bb0596c4b4edb833eb98b67bee1 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Tue, 25 Jun 2024 17:54:38 +0100 Subject: [PATCH] Bugfix/Add check for setError (#2721) add check for setError --- packages/ui/src/ui-component/button/FlowListMenu.jsx | 6 +++--- packages/ui/src/views/apikey/APIKeyDialog.jsx | 4 ++-- .../src/views/assistants/AssistantVectorStoreDialog.jsx | 9 ++++----- packages/ui/src/views/assistants/LoadAssistantDialog.jsx | 2 +- .../ui/src/views/credentials/AddEditCredentialDialog.jsx | 8 ++++---- packages/ui/src/views/tools/ToolDialog.jsx | 2 +- .../ui/src/views/variables/AddEditVariableDialog.jsx | 4 ++-- 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/ui/src/ui-component/button/FlowListMenu.jsx b/packages/ui/src/ui-component/button/FlowListMenu.jsx index 07c44104827..1a7e620b047 100644 --- a/packages/ui/src/ui-component/button/FlowListMenu.jsx +++ b/packages/ui/src/ui-component/button/FlowListMenu.jsx @@ -155,7 +155,7 @@ export default function FlowListMenu({ chatflow, isAgentCanvas, setError, update await updateChatflowApi.request(chatflow.id, updateBody) await updateFlowsApi.request() } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data, options: { @@ -194,7 +194,7 @@ export default function FlowListMenu({ chatflow, isAgentCanvas, setError, update await updateChatflowApi.request(chatflow.id, updateBody) await updateFlowsApi.request() } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data, options: { @@ -226,7 +226,7 @@ export default function FlowListMenu({ chatflow, isAgentCanvas, setError, update await chatflowsApi.deleteChatflow(chatflow.id) await updateFlowsApi.request() } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: typeof error.response.data === 'object' ? error.response.data.message : error.response.data, options: { diff --git a/packages/ui/src/views/apikey/APIKeyDialog.jsx b/packages/ui/src/views/apikey/APIKeyDialog.jsx index f305f13fb12..4b81102a79b 100644 --- a/packages/ui/src/views/apikey/APIKeyDialog.jsx +++ b/packages/ui/src/views/apikey/APIKeyDialog.jsx @@ -77,7 +77,7 @@ const APIKeyDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) => { onConfirm() } } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to add new API key: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data @@ -116,7 +116,7 @@ const APIKeyDialog = ({ show, dialogProps, onCancel, onConfirm, setError }) => { onConfirm() } } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to save API key: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data diff --git a/packages/ui/src/views/assistants/AssistantVectorStoreDialog.jsx b/packages/ui/src/views/assistants/AssistantVectorStoreDialog.jsx index e026583acf5..7e69b0af949 100644 --- a/packages/ui/src/views/assistants/AssistantVectorStoreDialog.jsx +++ b/packages/ui/src/views/assistants/AssistantVectorStoreDialog.jsx @@ -100,7 +100,7 @@ const AssistantVectorStoreDialog = ({ show, dialogProps, onCancel, onConfirm, on }, [listAssistantVectorStoreApi.data]) useEffect(() => { - if (getAssistantVectorStoreApi.error) { + if (getAssistantVectorStoreApi.error && setError) { setError(getAssistantVectorStoreApi.error) } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -152,7 +152,7 @@ const AssistantVectorStoreDialog = ({ show, dialogProps, onCancel, onConfirm, on } setLoading(false) } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to delete Vector Store: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data @@ -198,7 +198,7 @@ const AssistantVectorStoreDialog = ({ show, dialogProps, onCancel, onConfirm, on } setLoading(false) } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to add new Vector Store: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data @@ -249,8 +249,7 @@ const AssistantVectorStoreDialog = ({ show, dialogProps, onCancel, onConfirm, on } setLoading(false) } catch (error) { - console.error('error=', error) - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to save Vector Store: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data diff --git a/packages/ui/src/views/assistants/LoadAssistantDialog.jsx b/packages/ui/src/views/assistants/LoadAssistantDialog.jsx index 57dea792dd2..dc29e46d162 100644 --- a/packages/ui/src/views/assistants/LoadAssistantDialog.jsx +++ b/packages/ui/src/views/assistants/LoadAssistantDialog.jsx @@ -40,7 +40,7 @@ const LoadAssistantDialog = ({ show, dialogProps, onCancel, onAssistantSelected, }, [getAllAvailableAssistantsApi.data]) useEffect(() => { - if (getAllAvailableAssistantsApi.error) { + if (getAllAvailableAssistantsApi.error && setError) { setError(getAllAvailableAssistantsApi.error) } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx b/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx index 604cfd578b0..32988c758cf 100644 --- a/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx +++ b/packages/ui/src/views/credentials/AddEditCredentialDialog.jsx @@ -71,14 +71,14 @@ const AddEditCredentialDialog = ({ show, dialogProps, onCancel, onConfirm, setEr }, [getSpecificComponentCredentialApi.data]) useEffect(() => { - if (getSpecificCredentialApi.error) { + if (getSpecificCredentialApi.error && setError) { setError(getSpecificCredentialApi.error) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [getSpecificCredentialApi.error]) useEffect(() => { - if (getSpecificComponentCredentialApi.error) { + if (getSpecificComponentCredentialApi.error && setError) { setError(getSpecificComponentCredentialApi.error) } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -132,7 +132,7 @@ const AddEditCredentialDialog = ({ show, dialogProps, onCancel, onConfirm, setEr onConfirm(createResp.data.id) } } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to add new Credential: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data @@ -184,7 +184,7 @@ const AddEditCredentialDialog = ({ show, dialogProps, onCancel, onConfirm, setEr onConfirm(saveResp.data.id) } } catch (error) { - setError(error) + if (setError) setError(error) enqueueSnackbar({ message: `Failed to save Credential: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data diff --git a/packages/ui/src/views/tools/ToolDialog.jsx b/packages/ui/src/views/tools/ToolDialog.jsx index ff0e9e5b151..d21caba343b 100644 --- a/packages/ui/src/views/tools/ToolDialog.jsx +++ b/packages/ui/src/views/tools/ToolDialog.jsx @@ -161,7 +161,7 @@ const ToolDialog = ({ show, dialogProps, onUseTemplate, onCancel, onConfirm, set }, [getSpecificToolApi.data]) useEffect(() => { - if (getSpecificToolApi.error) { + if (getSpecificToolApi.error && setError) { setError(getSpecificToolApi.error) } // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/packages/ui/src/views/variables/AddEditVariableDialog.jsx b/packages/ui/src/views/variables/AddEditVariableDialog.jsx index b097735bfab..9647ffc0448 100644 --- a/packages/ui/src/views/variables/AddEditVariableDialog.jsx +++ b/packages/ui/src/views/variables/AddEditVariableDialog.jsx @@ -111,7 +111,7 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm, setErro onConfirm(createResp.data.id) } } catch (err) { - setError(err) + if (setError) setError(err) enqueueSnackbar({ message: `Failed to add new Variable: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data @@ -156,7 +156,7 @@ const AddEditVariableDialog = ({ show, dialogProps, onCancel, onConfirm, setErro onConfirm(saveResp.data.id) } } catch (error) { - setError(err) + if (setError) setError(err) enqueueSnackbar({ message: `Failed to save Variable: ${ typeof error.response.data === 'object' ? error.response.data.message : error.response.data