UBERF-8175 Better errors handling in uppy uploader (#6629)

This commit is contained in:
Alexander Onnikov 2024-09-19 11:35:22 +07:00 committed by GitHub
parent 8cf7929712
commit 0b3d500484
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 9 deletions

View File

@ -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}
<IconError size={'small'} fill={'var(--negative-button-default)'} />

View File

@ -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<Blob>
if (uuid !== undefined) {
const metadata = await getFileMetadata(file.data, uuid)