mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-31 04:38:02 +00: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="container flex-row-center flex-gap-2 active"
|
||||||
class:error={state.error}
|
class:error={state.error}
|
||||||
on:click={handleClick}
|
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}
|
{#if state.error}
|
||||||
<IconError size={'small'} fill={'var(--negative-button-default)'} />
|
<IconError size={'small'} fill={'var(--negative-button-default)'} />
|
||||||
|
@ -76,15 +76,19 @@ export function getUppy (options: FileUploadOptions, onFileUploaded?: FileUpload
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: 'Bearer ' + (getMetadata(presentation.metadata.Token) as string)
|
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[]) => {
|
uppy.addPreProcessor(async (fileIds: string[]) => {
|
||||||
for (const fileId of fileIds) {
|
for (const fileId of fileIds) {
|
||||||
const file = uppy.getFile(fileId)
|
const file = uppy.getFile(fileId)
|
||||||
@ -98,8 +102,12 @@ export function getUppy (options: FileUploadOptions, onFileUploaded?: FileUpload
|
|||||||
|
|
||||||
if (onFileUploaded != null) {
|
if (onFileUploaded != null) {
|
||||||
uppy.addPostProcessor(async (fileIds: string[]) => {
|
uppy.addPostProcessor(async (fileIds: string[]) => {
|
||||||
for (const fileId of fileIds) {
|
// post-process only files without errors
|
||||||
const file = uppy.getFile(fileId)
|
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>
|
const uuid = file.meta.uuid as Ref<Blob>
|
||||||
if (uuid !== undefined) {
|
if (uuid !== undefined) {
|
||||||
const metadata = await getFileMetadata(file.data, uuid)
|
const metadata = await getFileMetadata(file.data, uuid)
|
||||||
|
Loading…
Reference in New Issue
Block a user