From: Sander Saarend Date: Thu, 29 Jun 2023 02:53:15 +0000 (+0300) Subject: Add error toast for 413 content too large response on image uploads (#1675) X-Git-Url: http://these/git/%7B%60/feeds/front/static/%7Bthis.captchaPngSrc%28%29%7D?a=commitdiff_plain;h=bca438b2c694ea6c3a8020affb1e2a44a200bd8c;p=lemmy-ui.git Add error toast for 413 content too large response on image uploads (#1675) Co-authored-by: SleeplessOne1917 --- diff --git a/src/shared/components/common/image-upload-form.tsx b/src/shared/components/common/image-upload-form.tsx index e8005cc..854e710 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 f7c4760..5623ace 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 149ff03..4108e7a 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 25a0fcc..c29d3b1 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"); }