Skip to content

Commit 628ad14

Browse files
committed
ai-plugin: fix log fetch failures
Signed-off-by: ashu8912 <[email protected]>
1 parent dab1c60 commit 628ad14

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

ai-assistant/src/helper/apihelper.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,16 @@ export const handleActualApiRequest = async (
393393
...requestOptions,
394394
isJSON: !isLogRequest(cleanedUrl),
395395
});
396+
console.log('API response received:', response);
396397
} catch (apiError) {
397-
console.log('Error in clusterRequest:', apiError);
398-
399398
// Handle specific multi-container pod logs error
400399
if (
401400
isLogRequest(cleanedUrl) &&
402401
apiError.message &&
403-
apiError.message?.includes('a container name must be specified')
402+
(apiError.message?.includes('a container name must be specified') ||
403+
apiError.message?.includes('container name must be specified') ||
404+
(apiError.message?.includes('Bad Request') && cleanedUrl.includes('/log')) ||
405+
apiError.message?.includes('choose one of'))
404406
) {
405407
// Extract pod name and available containers from error message
406408
const podMatch = apiError.message.match(/for pod ([^,]+)/);
@@ -425,12 +427,33 @@ export const handleActualApiRequest = async (
425427
role: 'assistant',
426428
content: errorContent,
427429
});
430+
} else {
431+
// If we can't parse the specific error but know it's a log request with Bad Request
432+
// Extract pod name from URL and suggest getting pod details
433+
const podNameFromUrl = cleanedUrl.match(/\/pods\/([^\/]+)\/log/);
434+
if (podNameFromUrl) {
435+
const podName = podNameFromUrl[1];
436+
437+
const errorContent = `Failed to get logs from pod "${podName}". This is likely because it has multiple containers.\n\nTo see the containers in this pod, I need to get the pod details first. Would you like me to check the pod details to see available containers?`;
438+
439+
aiManager.history.push({
440+
error: false,
441+
role: 'assistant',
442+
content: errorContent,
443+
});
444+
445+
return JSON.stringify({
446+
error: false,
447+
role: 'assistant',
448+
content: errorContent,
449+
});
450+
}
428451
}
429452
}
430453

431454
// Handle general API errors
432455
if (onFailure) {
433-
onFailure(apiError, 'GET', { type: 'api_error' });
456+
// onFailure(apiError, 'GET', { type: 'api_error' });
434457
}
435458
aiManager.history.push({
436459
error: true,

0 commit comments

Comments
 (0)