Fix upload error not displayed in DocumentUpload component

Wrap store.upload() calls in try-catch in both onFileSelect and onDrop
so thrown errors (e.g. file too large) don't bubble up unhandled.
Display store.error inline below the upload hint so users see why
their upload was rejected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Pier-Jean Malandrino 2026-03-31 11:14:33 +02:00
parent 0af3b81b8f
commit 6b0fc45e5d

View file

@ -18,6 +18,7 @@
</svg>
<span class="upload-text">{{ t('upload.drop') }}</span>
<span class="upload-hint">{{ t('upload.maxSize') }}</span>
<span v-if="store.error" class="upload-error">{{ store.error }}</span>
</div>
</div>
</template>
@ -42,8 +43,13 @@ async function onFileSelect(e: Event) {
const target = e.target as HTMLInputElement
const file = target.files?.[0]
if (file) {
const doc = await store.upload(file)
if (doc) emit('uploaded', doc.id)
try {
store.clearError()
const doc = await store.upload(file)
if (doc) emit('uploaded', doc.id)
} catch {
// error is already set in store.upload
}
}
target.value = ''
}
@ -52,8 +58,13 @@ async function onDrop(e: DragEvent) {
dragging.value = false
const file = e.dataTransfer?.files?.[0]
if (file && file.type === 'application/pdf') {
const doc = await store.upload(file)
if (doc) emit('uploaded', doc.id)
try {
store.clearError()
const doc = await store.upload(file)
if (doc) emit('uploaded', doc.id)
} catch {
// error is already set in store.upload
}
}
}
</script>
@ -103,6 +114,12 @@ async function onDrop(e: DragEvent) {
color: var(--text-muted);
}
.upload-error {
font-size: 13px;
color: var(--error, #e53e3e);
font-weight: 500;
}
.spinner {
width: 24px;
height: 24px;