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:
@@ -260,11 +260,6 @@ export function useCrawlUrl() {
|
||||
return response;
|
||||
},
|
||||
onError: (error, _variables, context) => {
|
||||
console.log(`🔍 [Crawl Hook] Received error:`, error);
|
||||
console.log(`🔍 [Crawl Hook] Error type: ${typeof error}`);
|
||||
console.log(`🔍 [Crawl Hook] Error keys:`, Object.keys(error || {}));
|
||||
console.log(`🔍 [Crawl Hook] Is OpenAI error:`, (error as EnhancedError)?.isOpenAIError);
|
||||
|
||||
// Rollback optimistic updates on error
|
||||
if (context?.previousKnowledge) {
|
||||
queryClient.setQueryData(knowledgeKeys.lists(), context.previousKnowledge);
|
||||
@@ -284,7 +279,6 @@ export function useCrawlUrl() {
|
||||
? getDisplayErrorMessage(error as EnhancedError)
|
||||
: (error instanceof Error ? error.message : "Failed to start crawl");
|
||||
|
||||
console.log(`🔍 [Crawl Hook] Final error message for toast:`, errorMessage);
|
||||
showToast(errorMessage, "error");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,6 @@ function isSafeObject(obj: any): boolean {
|
||||
* Parse and enhance API errors from knowledge base operations
|
||||
*/
|
||||
export function parseKnowledgeBaseError(error: any): EnhancedError {
|
||||
console.log(`🔍 [Error Parser] Input error:`, error);
|
||||
console.log(`🔍 [Error Parser] Error type: ${typeof error}`);
|
||||
console.log(`🔍 [Error Parser] Error keys:`, Object.keys(error || {}));
|
||||
|
||||
// Enhanced input validation
|
||||
if (!error) {
|
||||
return createFallbackError('No error information provided');
|
||||
@@ -107,24 +103,14 @@ export function parseKnowledgeBaseError(error: any): EnhancedError {
|
||||
// Prioritize error.detail (where we put structured OpenAI error data)
|
||||
const errorData = error.detail || error.error;
|
||||
|
||||
console.log(`🔍 [Error Parser] Error data:`, errorData);
|
||||
console.log(`🔍 [Error Parser] Error data type:`, typeof errorData);
|
||||
console.log(`🔍 [Error Parser] Has error_type:`, errorData?.error_type);
|
||||
|
||||
// Check if it's an OpenAI-specific error
|
||||
if (typeof errorData === 'object' && errorData?.error_type) {
|
||||
console.log(`🔍 [Error Parser] Detected OpenAI error type: ${errorData.error_type}`);
|
||||
enhancedError.isOpenAIError = true;
|
||||
enhancedError.errorDetails = errorData as OpenAIErrorDetails;
|
||||
|
||||
// Override the message with the detailed error message
|
||||
enhancedError.message = errorData.message || errorData.error || enhancedError.message;
|
||||
console.log(`🔍 [Error Parser] Set enhanced message: ${enhancedError.message}`);
|
||||
} else {
|
||||
console.log(`🔍 [Error Parser] Not an OpenAI error - errorData type: ${typeof errorData}, has error_type: ${!!errorData?.error_type}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`🔍 [Error Parser] No error.detail or error.error found`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user