From 0b3d500484cac113c4b36a1c0e13eed41b5b4963 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Thu, 19 Sep 2024 11:35:22 +0700 Subject: [PATCH] UBERF-8175 Better errors handling in uppy uploader (#6629) --- .../src/components/FileUploadStatusBar.svelte | 2 +- plugins/uploader-resources/src/uppy.ts | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte b/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte index a7070e0df7..d3cfcdcada 100644 --- a/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte +++ b/plugins/uploader-resources/src/components/FileUploadStatusBar.svelte @@ -65,7 +65,7 @@ class="container flex-row-center flex-gap-2 active" class:error={state.error} on:click={handleClick} - use:tooltip={state.error !== undefined ? { label: getEmbeddedLabel(state.error) } : undefined} + use:tooltip={state.error != null ? { label: getEmbeddedLabel(state.error) } : undefined} > {#if state.error} diff --git a/plugins/uploader-resources/src/uppy.ts b/plugins/uploader-resources/src/uppy.ts index 8e197800ef..84a7316e2d 100644 --- a/plugins/uploader-resources/src/uppy.ts +++ b/plugins/uploader-resources/src/uppy.ts @@ -76,15 +76,19 @@ export function getUppy (options: FileUploadOptions, onFileUploaded?: FileUpload method: 'POST', headers: { Authorization: 'Bearer ' + (getMetadata(presentation.metadata.Token) as string) + }, + getResponseError: (_, response) => { + return new Error((response as Response).statusText) } - // getResponseData: (body: string): UppyBody => { - // const data = JSON.parse(body) - // return { - // uuid: data[0].id - // } - // } }) + // Hack to setup shouldRetry callback on xhrUpload that is not exposed in options + const xhrUpload = uppy.getState().xhrUpload ?? {} + uppy.getState().xhrUpload = { + ...xhrUpload, + shouldRetry: (response: Response) => response.status !== 413 + } + uppy.addPreProcessor(async (fileIds: string[]) => { for (const fileId of fileIds) { const file = uppy.getFile(fileId) @@ -98,8 +102,12 @@ export function getUppy (options: FileUploadOptions, onFileUploaded?: FileUpload if (onFileUploaded != null) { uppy.addPostProcessor(async (fileIds: string[]) => { - for (const fileId of fileIds) { - const file = uppy.getFile(fileId) + // post-process only files without errors + const files = fileIds + .map((fileId) => uppy.getFile(fileId)) + .filter((file) => !('error' in file && file.error != null)) + + for (const file of files) { const uuid = file.meta.uuid as Ref if (uuid !== undefined) { const metadata = await getFileMetadata(file.data, uuid)