mirror of
https://github.com/coleam00/Archon.git
synced 2026-01-01 04:09:08 -05:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user