Enhance API response handling and implement unified API standard across multiple modules. Added feature flags for unified exception handling and debug throttling in settings. Updated pagination and response formats in various viewsets to align with the new standard. Improved error handling and response validation in frontend components for better user feedback.

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-15 20:18:42 +00:00
parent 94f243f4a2
commit a75ebf2584
18 changed files with 1974 additions and 642 deletions

View File

@@ -75,7 +75,10 @@ export default function Prompts() {
try {
const promises = PROMPT_TYPES.map(async (type) => {
try {
const data = await fetchAPI(`/v1/system/prompts/by_type/${type.key}/`);
const response = await fetchAPI(`/v1/system/prompts/by_type/${type.key}/`);
// Extract data field from unified API response format
// Response format: { success: true, data: {...}, request_id: "..." }
const data = response?.data || response;
return { key: type.key, data };
} catch (error) {
console.error(`Error loading prompt ${type.key}:`, error);
@@ -116,7 +119,7 @@ export default function Prompts() {
setSaving({ ...saving, [promptType]: true });
try {
const data = await fetchAPI('/v1/system/prompts/save/', {
const response = await fetchAPI('/v1/system/prompts/save/', {
method: 'POST',
body: JSON.stringify({
prompt_type: promptType,
@@ -124,11 +127,15 @@ export default function Prompts() {
}),
});
if (data.success) {
toast.success(data.message || 'Prompt saved successfully');
// Extract data field from unified API response format
// Response format: { success: true, data: {...}, message: "...", request_id: "..." }
const data = response?.data || response;
if (response.success) {
toast.success(response.message || 'Prompt saved successfully');
await loadPrompts(); // Reload to get updated data
} else {
throw new Error(data.error || 'Failed to save prompt');
throw new Error(response.error || 'Failed to save prompt');
}
} catch (error: any) {
console.error('Error saving prompt:', error);
@@ -145,18 +152,22 @@ export default function Prompts() {
setSaving({ ...saving, [promptType]: true });
try {
const data = await fetchAPI('/v1/system/prompts/reset/', {
const response = await fetchAPI('/v1/system/prompts/reset/', {
method: 'POST',
body: JSON.stringify({
prompt_type: promptType,
}),
});
if (data.success) {
toast.success(data.message || 'Prompt reset to default');
// Extract data field from unified API response format
// Response format: { success: true, data: {...}, message: "...", request_id: "..." }
const data = response?.data || response;
if (response.success) {
toast.success(response.message || 'Prompt reset to default');
await loadPrompts(); // Reload to get default value
} else {
throw new Error(data.error || 'Failed to reset prompt');
throw new Error(response.error || 'Failed to reset prompt');
}
} catch (error: any) {
console.error('Error resetting prompt:', error);