Enhance billing and subscription management: Added payment method checks in ProtectedRoute, improved error handling in billing components, and optimized API calls to reduce throttling. Updated user account handling in various components to ensure accurate plan and subscription data display.
This commit is contained in:
@@ -154,6 +154,20 @@ export async function fetchAPI(endpoint: string, options?: RequestInit & { timeo
|
||||
// Read response body once (can only be consumed once)
|
||||
const text = await response.text();
|
||||
|
||||
// Handle 402/403 for plan/limits gracefully by tagging error
|
||||
if (response.status === 402 || response.status === 403) {
|
||||
let err: any = new Error(response.statusText);
|
||||
err.status = response.status;
|
||||
try {
|
||||
const parsed = text ? JSON.parse(text) : null;
|
||||
err.message = parsed?.error || parsed?.message || response.statusText;
|
||||
err.data = parsed;
|
||||
} catch (_) {
|
||||
err.message = text || response.statusText;
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Handle 403 Forbidden with authentication error - clear invalid tokens
|
||||
if (response.status === 403) {
|
||||
try {
|
||||
@@ -1659,6 +1673,9 @@ export interface ModuleSetting {
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
// Deduplicate module-enable fetches to prevent 429s for normal users
|
||||
let moduleEnableSettingsInFlight: Promise<ModuleEnableSettings> | null = null;
|
||||
|
||||
export async function fetchModuleSettings(moduleName: string): Promise<ModuleSetting[]> {
|
||||
// fetchAPI extracts data from unified format {success: true, data: [...]}
|
||||
// So response IS the array, not an object with results
|
||||
@@ -1674,8 +1691,17 @@ export async function createModuleSetting(data: { module_name: string; key: stri
|
||||
}
|
||||
|
||||
export async function fetchModuleEnableSettings(): Promise<ModuleEnableSettings> {
|
||||
const response = await fetchAPI('/v1/system/settings/modules/enable/');
|
||||
return response;
|
||||
if (moduleEnableSettingsInFlight) {
|
||||
return moduleEnableSettingsInFlight;
|
||||
}
|
||||
|
||||
moduleEnableSettingsInFlight = fetchAPI('/v1/system/settings/modules/enable/');
|
||||
try {
|
||||
const response = await moduleEnableSettingsInFlight;
|
||||
return response;
|
||||
} finally {
|
||||
moduleEnableSettingsInFlight = null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateModuleEnableSettings(data: Partial<ModuleEnableSettings>): Promise<ModuleEnableSettings> {
|
||||
|
||||
Reference in New Issue
Block a user