From db7f82422e89cc45627bc70d6ef7eab9732465a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20S=C3=A1nchez?= Date: Mon, 26 Dec 2022 06:25:35 +0100 Subject: [PATCH] feat: file upload error handling (#560) --- components/publish/PublishWidget.vue | 47 +++++++++++++++++++++++++--- locales/en-US.json | 2 ++ locales/es-ES.json | 2 ++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index a1991e2e..2cf5294d 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -54,6 +54,7 @@ const currentVisibility = $computed(() => { }) let isUploading = $ref(false) +let failed = $ref([]) async function handlePaste(evt: ClipboardEvent) { const files = evt.clipboardData?.files @@ -98,11 +99,19 @@ const masto = useMasto() async function uploadAttachments(files: File[]) { isUploading = true + failed = [] for (const file of files) { - const attachment = await masto.mediaAttachments.create({ - file, - }) - draft.attachments.push(attachment) + try { + const attachment = await masto.mediaAttachments.create({ + file, + }) + draft.attachments.push(attachment) + } + catch (e) { + // TODO: add some human-readable error message, problem is that masto api will not return response code + console.error(e) + failed = [...failed, file] + } } isUploading = false } @@ -220,6 +229,36 @@ defineExpose({
{{ $t('state.uploading') }}
+
+ +
+ + + + + +
    +
  1. + {{ file.name }} +
  2. +
+