Added error when ingest fails too

This commit is contained in:
Lucas Oliveira 2025-12-03 17:30:30 -03:00
parent 89a2d697b3
commit 2ca741ed32
4 changed files with 45 additions and 0 deletions

View file

@ -158,6 +158,16 @@ const OnboardingUpload = ({ onComplete }: OnboardingUploadProps) => {
const errorMessage = error instanceof Error ? error.message : "Upload failed";
console.error("Upload failed", errorMessage);
// Dispatch event that chat context can listen to
// This avoids circular dependency issues
if (typeof window !== "undefined") {
window.dispatchEvent(
new CustomEvent("ingestionFailed", {
detail: { source: "onboarding" },
}),
);
}
// Show error toast notification
toast.error("Document upload failed", {
description: errorMessage,

View file

@ -238,6 +238,15 @@ export function KnowledgeDropdown() {
await uploadFileUtil(file, replace);
refetchTasks();
} catch (error) {
// Dispatch event that chat context can listen to
// This avoids circular dependency issues
if (typeof window !== "undefined") {
window.dispatchEvent(
new CustomEvent("ingestionFailed", {
detail: { source: "knowledge-dropdown" },
}),
);
}
toast.error("Upload failed", {
description: error instanceof Error ? error.message : "Unknown error",
});

View file

@ -112,6 +112,18 @@ export function ChatProvider({ children }: ChatProviderProps) {
useState<KnowledgeFilter | null>(null);
const [hasChatError, setChatError] = useState(false);
// Listen for ingestion failures and set chat error flag
useEffect(() => {
const handleIngestionFailed = () => {
setChatError(true);
};
window.addEventListener("ingestionFailed", handleIngestionFailed);
return () => {
window.removeEventListener("ingestionFailed", handleIngestionFailed);
};
}, []);
// Debounce refresh requests to prevent excessive reloads
const refreshTimeoutRef = useRef<NodeJS.Timeout | null>(null);

View file

@ -323,6 +323,20 @@ export function TaskProvider({ children }: { children: React.ReactNode }) {
currentTask.error || "Unknown error"
}`,
});
// Set chat error flag to trigger test_completion=true on health checks
// Only for ingestion-related tasks (tasks with files are ingestion tasks)
if (currentTask.files && Object.keys(currentTask.files).length > 0) {
// Dispatch event that chat context can listen to
// This avoids circular dependency issues
if (typeof window !== "undefined") {
window.dispatchEvent(
new CustomEvent("ingestionFailed", {
detail: { taskId: currentTask.task_id },
}),
);
}
}
}
}
});