From bca438b2c694ea6c3a8020affb1e2a44a200bd8c Mon Sep 17 00:00:00 2001 From: Sander Saarend Date: Thu, 29 Jun 2023 05:53:15 +0300 Subject: [PATCH] Add error toast for 413 content too large response on image uploads (#1675) Co-authored-by: SleeplessOne1917 --- src/shared/components/common/image-upload-form.tsx | 2 ++ src/shared/components/common/markdown-textarea.tsx | 4 ++++ src/shared/components/home/emojis-form.tsx | 2 ++ src/shared/components/post/post-form.tsx | 2 ++ 4 files changed, 10 insertions(+) diff --git a/src/shared/components/common/image-upload-form.tsx b/src/shared/components/common/image-upload-form.tsx index e8005ccc..854e7105 100644 --- a/src/shared/components/common/image-upload-form.tsx +++ b/src/shared/components/common/image-upload-form.tsx @@ -84,6 +84,8 @@ export class ImageUploadForm extends Component< if (res.state === "success") { if (res.data.msg === "ok") { i.props.onUpload(res.data.url as string); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); } else { toast(JSON.stringify(res), "danger"); } diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index f7c4760a..5623ace5 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -443,6 +443,10 @@ export class MarkdownTextArea extends Component< const textarea: any = document.getElementById(i.id); autosize.update(textarea); pictrsDeleteToast(image.name, res.data.delete_url as string); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); + i.setState({ imageUploadStatus: undefined }); + throw JSON.stringify(res.data); } else { throw JSON.stringify(res.data); } diff --git a/src/shared/components/home/emojis-form.tsx b/src/shared/components/home/emojis-form.tsx index 149ff032..4108e7a4 100644 --- a/src/shared/components/home/emojis-form.tsx +++ b/src/shared/components/home/emojis-form.tsx @@ -508,6 +508,8 @@ export class EmojiForm extends Component { { form: form, index: index, overrideValue: res.data.url as string }, event ); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); } else { toast(JSON.stringify(res), "danger"); } diff --git a/src/shared/components/post/post-form.tsx b/src/shared/components/post/post-form.tsx index 25a0fcc0..c29d3b1f 100644 --- a/src/shared/components/post/post-form.tsx +++ b/src/shared/components/post/post-form.tsx @@ -187,6 +187,8 @@ function handleImageUpload(i: PostForm, event: any) { imageLoading: false, imageDeleteUrl: res.data.delete_url as string, }); + } else if (res.data.msg === "too_large") { + toast(I18NextService.i18n.t("upload_too_large"), "danger"); } else { toast(JSON.stringify(res), "danger"); }