mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 03:14:40 +03:00
UBERF-8175 Better errors handling in uppy uploader (#6629)
This commit is contained in:
parent
8cf7929712
commit
0b3d500484
@ -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)'} />
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user