mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 07:35:53 +08:00
fix: improve error handling and default values in fetchPlan function (#17320)
This commit is contained in:
parent
0bf816f2e8
commit
5cffcd6336
@ -111,20 +111,37 @@ export const ProviderContextProvider = ({
|
|||||||
const { data: isEducationAccount } = useEducationStatus(!enableEducationPlan)
|
const { data: isEducationAccount } = useEducationStatus(!enableEducationPlan)
|
||||||
|
|
||||||
const fetchPlan = async () => {
|
const fetchPlan = async () => {
|
||||||
const data = await fetchCurrentPlanInfo()
|
try {
|
||||||
const enabled = data.billing.enabled
|
const data = await fetchCurrentPlanInfo()
|
||||||
setEnableBilling(enabled)
|
if (!data) {
|
||||||
setEnableEducationPlan(data.education.enabled)
|
console.error('Failed to fetch plan info: data is undefined')
|
||||||
setIsEducationWorkspace(data.education.activated)
|
return
|
||||||
setEnableReplaceWebAppLogo(data.can_replace_logo)
|
}
|
||||||
if (enabled) {
|
|
||||||
setPlan(parseCurrentPlan(data) as any)
|
// set default value to avoid undefined error
|
||||||
setIsFetchedPlan(true)
|
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(() => {
|
useEffect(() => {
|
||||||
fetchPlan()
|
fetchPlan()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user