UBER-391 Unknown error error (#3410)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-06-08 21:59:17 +06:00 committed by GitHub
parent d553a261d8
commit 9fb1c64216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -52,5 +52,8 @@
"UnPinAttachment": "Mark less important",
"FilterAttachments": "Attachments",
"RemovedAttachment": "Removed attachment"
},
"status": {
"FileTooLarge": "File too large"
}
}

View File

@ -52,5 +52,8 @@
"UnPinAttachment": "Убрать пометку важное",
"FilterAttachments": "Вложения",
"RemovedAttachment": "Удалил(а) вложение"
},
"status": {
"FileTooLarge": "Файл слишком большой"
}
}

View File

@ -15,7 +15,7 @@
//
import attachment, { attachmentId } from '@hcengineering/attachment'
import type { IntlString } from '@hcengineering/platform'
import type { IntlString, StatusCode } from '@hcengineering/platform'
import { mergeIds } from '@hcengineering/platform'
import { ViewAction } from '@hcengineering/view'
@ -43,6 +43,9 @@ export default mergeIds(attachmentId, attachment, {
RemoveAttachmentFromSaved: '' as IntlString,
Pinned: '' as IntlString
},
status: {
FileTooLarge: '' as StatusCode
},
actionImpl: {
AddAttachmentToSaved: '' as ViewAction,
DeleteAttachmentFromSaved: '' as ViewAction,

View File

@ -17,7 +17,7 @@
import { Attachment } from '@hcengineering/attachment'
import { Class, concatLink, Data, Doc, Ref, Space, TxOperations as Client } from '@hcengineering/core'
import presentation from '@hcengineering/presentation'
import { getMetadata, setPlatformStatus, unknownError } from '@hcengineering/platform'
import { PlatformError, Severity, Status, getMetadata, setPlatformStatus, unknownError } from '@hcengineering/platform'
import attachment from './plugin'
@ -40,7 +40,11 @@ export async function uploadFile (file: File): Promise<string> {
})
if (resp.status !== 200) {
throw Error(`Failed to upload file: ${resp.statusText}`)
if (resp.status === 413) {
throw new PlatformError(new Status(Severity.ERROR, attachment.status.FileTooLarge, {}))
} else {
throw Error(`Failed to upload file: ${resp.statusText}`)
}
}
return await resp.text()