From 9fb1c6421651c2186a6e6b5517bd9046d5a4c651 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 8 Jun 2023 21:59:17 +0600 Subject: [PATCH] UBER-391 Unknown error error (#3410) Signed-off-by: Denis Bykhov --- plugins/attachment-assets/lang/en.json | 3 +++ plugins/attachment-assets/lang/ru.json | 3 +++ plugins/attachment-resources/src/plugin.ts | 5 ++++- plugins/attachment-resources/src/utils.ts | 8 ++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/attachment-assets/lang/en.json b/plugins/attachment-assets/lang/en.json index 21772f8854..5a66a0720e 100644 --- a/plugins/attachment-assets/lang/en.json +++ b/plugins/attachment-assets/lang/en.json @@ -52,5 +52,8 @@ "UnPinAttachment": "Mark less important", "FilterAttachments": "Attachments", "RemovedAttachment": "Removed attachment" + }, + "status": { + "FileTooLarge": "File too large" } } diff --git a/plugins/attachment-assets/lang/ru.json b/plugins/attachment-assets/lang/ru.json index f324741ea6..bbff81b033 100644 --- a/plugins/attachment-assets/lang/ru.json +++ b/plugins/attachment-assets/lang/ru.json @@ -52,5 +52,8 @@ "UnPinAttachment": "Убрать пометку важное", "FilterAttachments": "Вложения", "RemovedAttachment": "Удалил(а) вложение" + }, + "status": { + "FileTooLarge": "Файл слишком большой" } } diff --git a/plugins/attachment-resources/src/plugin.ts b/plugins/attachment-resources/src/plugin.ts index 6cf916e30b..05cef6645d 100644 --- a/plugins/attachment-resources/src/plugin.ts +++ b/plugins/attachment-resources/src/plugin.ts @@ -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, diff --git a/plugins/attachment-resources/src/utils.ts b/plugins/attachment-resources/src/utils.ts index e9971e01bc..c6d9ba57fc 100644 --- a/plugins/attachment-resources/src/utils.ts +++ b/plugins/attachment-resources/src/utils.ts @@ -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 { }) 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()