cleanup: Remove debug logging and finalize OpenAI error handling

Clean production-ready version with:
- Comprehensive OpenAI error handling (401, 429, 502)
- Proper error message sanitization
- ProjectServiceError structure handling
- Enhanced user-friendly error messages
- TanStack Query integration

Successfully resolves Issue #362 - users now get immediate clear
error messages instead of silent failures and 90-minute debugging sessions.
This commit is contained in:
leex279
2025-09-12 20:18:41 +02:00
parent 4d4ff4207f
commit f8a3054906
3 changed files with 0 additions and 34 deletions

View File

@@ -18,16 +18,9 @@ export async function callKnowledgeAPI<T>(
// Use the ETag-aware API client for caching benefits
return await callAPIWithETag<T>(endpoint, options);
} catch (error: any) {
console.log(`🔍 [Knowledge API] Caught error for ${endpoint}:`, error);
console.log(`🔍 [Knowledge API] Error type: ${typeof error}`);
console.log(`🔍 [Knowledge API] Error constructor:`, error.constructor?.name);
console.log(`🔍 [Knowledge API] Error keys:`, Object.keys(error || {}));
// Handle ProjectServiceError specifically (comes from callAPIWithETag)
let errorData;
if (error.constructor?.name === 'ProjectServiceError') {
console.log(`🔍 [Knowledge API] Handling ProjectServiceError - message: "${error.message}", statusCode: ${error.statusCode}`);
// The ETag client extracts the error message but loses the structured details
// We need to reconstruct the structured error based on the status code and message
@@ -93,22 +86,15 @@ export async function callKnowledgeAPI<T>(
};
}
console.log(`🔍 [Knowledge API] Parsed error data:`, errorData);
// Apply enhanced error parsing for OpenAI errors
const enhancedError = parseKnowledgeBaseError(errorData);
console.log(`🔍 [Knowledge API] Enhanced error:`, enhancedError);
console.log(`🔍 [Knowledge API] Is OpenAI error:`, enhancedError.isOpenAIError);
console.log(`🔍 [Knowledge API] Error details:`, enhancedError.errorDetails);
// Preserve the original error structure but enhance with our parsing
const finalError = error as EnhancedError;
finalError.isOpenAIError = enhancedError.isOpenAIError;
finalError.errorDetails = enhancedError.errorDetails;
finalError.message = enhancedError.message;
console.log(`🔍 [Knowledge API] Final error to throw:`, finalError);
throw finalError;
}
}