fix: improve project file upload error handling

- Add null check for projectId before file upload
- Wrap loadProjectData in try-catch after upload
- Show detailed error messages on upload failure
- Fix document filter to use strict equality
This commit is contained in:
2026-01-07 14:59:06 +01:00
parent 298fb9681e
commit 07d3e07fd6

View File

@@ -73,14 +73,14 @@
links = linksResult.data;
}
// Load documents (filter by projectId when we implement that)
// For now, load all documents - TODO: filter by projectId
// Load documents filtered by projectId
isLoadingDocs = true;
try {
const allDocs = await listDocuments();
// Filter documents by projectId (once we add that field)
documents = allDocs.filter(d => (d as any).projectId === projectId);
} catch {
// Filter documents by projectId - strict equality
documents = allDocs.filter(d => d.projectId === projectId);
} catch (err) {
console.error('Failed to load documents:', err);
documents = [];
} finally {
isLoadingDocs = false;
@@ -181,6 +181,11 @@
}
async function processFiles(files: File[]) {
if (!projectId) {
toastState.error('Project ID not available');
return;
}
isUploading = true;
for (const file of files) {
@@ -194,17 +199,22 @@
// Add document with projectId
await addDocument(file.name, content, file.type || 'text/plain', {
embeddingModel: DEFAULT_EMBEDDING_MODEL,
projectId
projectId: projectId
});
toastState.success(`Added "${file.name}" to project`);
} catch (error) {
console.error(`Failed to process ${file.name}:`, error);
toastState.error(`Failed to add "${file.name}"`);
const message = error instanceof Error ? error.message : 'Unknown error';
toastState.error(`Failed to add "${file.name}": ${message}`);
}
}
await loadProjectData();
try {
await loadProjectData();
} catch (err) {
console.error('Failed to reload project data:', err);
}
isUploading = false;
}