Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: improve error handling and default values in fetchPlan function (#17320)

akou5cffcd633646
diff --git a/web/context/provider-context.tsx b/web/context/provider-context.tsx
index 67c389167d4..ce3e15e8b84 100644
--- a/web/context/provider-context.tsx
+++ b/web/context/provider-context.tsx
@@ -111,20 +111,37 @@ export const ProviderContextProvider = ({
const { data: isEducationAccount } = useEducationStatus(!enableEducationPlan)
const fetchPlan = async () => {
- const data = await fetchCurrentPlanInfo()
- const enabled = data.billing.enabled
- setEnableBilling(enabled)
- setEnableEducationPlan(data.education.enabled)
- setIsEducationWorkspace(data.education.activated)
- setEnableReplaceWebAppLogo(data.can_replace_logo)
- if (enabled) {
- setPlan(parseCurrentPlan(data) as any)
- setIsFetchedPlan(true)
+ try {
+ const data = await fetchCurrentPlanInfo()
+ if (!data) {
+ console.error('Failed to fetch plan info: data is undefined')
+ return
+ }
+
+ // set default value to avoid undefined error
+ setEnableBilling(data.billing?.enabled ?? false)
+ setEnableEducationPlan(data.education?.enabled ?? false)
+ setIsEducationWorkspace(data.education?.activated ?? false)
+ setEnableReplaceWebAppLogo(data.can_replace_logo ?? false)
+
+ if (data.billing?.enabled) {
+ setPlan(parseCurrentPlan(data) as any)
+ setIsFetchedPlan(true)
+ }
+
+ if (data.model_load_balancing_enabled)
+ setModelLoadBalancingEnabled(true)
+ if (data.dataset_operator_enabled)
+ setDatasetOperatorEnabled(true)
+ }
+ catch (error) {
+ console.error('Failed to fetch plan info:', error)
+ // set default value to avoid undefined error
+ setEnableBilling(false)
+ setEnableEducationPlan(false)
+ setIsEducationWorkspace(false)
+ setEnableReplaceWebAppLogo(false)
}
- if (data.model_load_balancing_enabled)
- setModelLoadBalancingEnabled(true)
- if (data.dataset_operator_enabled)
- setDatasetOperatorEnabled(true)
}
useEffect(() => {
fetchPlan()