Implement unified API standard across backend viewsets and serializers, enhancing error handling and response formatting. Update AccountModelViewSet to standardize CRUD operations with success and error responses. Refactor various viewsets to inherit from AccountModelViewSet, ensuring compliance with the new standard. Improve frontend components to handle API responses consistently and update configuration for better user experience.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-15 23:04:31 +00:00
parent 5a3706d997
commit 0ec594363c
11 changed files with 593 additions and 113 deletions

View File

@@ -640,18 +640,33 @@ export async function autoClusterKeywords(keywordIds: number[], sectorId?: numbe
const requestBody = { ids: keywordIds, sector_id: sectorId };
try {
// fetchAPI will automatically extract data from unified format
// For action endpoints, response is {success: true, data: {...}}
// fetchAPI extracts and returns the data field, so response should already be the data object
const response = await fetchAPI(endpoint, {
method: 'POST',
body: JSON.stringify(requestBody),
});
// Check if response indicates an error (success: false)
if (response && response.success === false) {
// Return error response as-is so caller can check result.success
return response;
// After fetchAPI processing, response should be the data object (not wrapped in success/data)
// But check if it's still wrapped (shouldn't happen, but for safety)
if (response && typeof response === 'object') {
if ('success' in response && response.success === false) {
// Error response - return as-is
return response as any;
}
// If response has data field, extract it
if ('data' in response && response.data) {
return { success: true, ...response.data } as any;
}
// Response is already the data object (after fetchAPI extraction)
// Ensure it has success: true
if (!('success' in response)) {
return { success: true, ...response } as any;
}
}
return response;
return response as any;
} catch (error: any) {
throw error;
}