]> Untitled Git - lemmy-ui.git/commitdiff
Add error toast for 413 content too large response on image uploads (#1675)
authorSander Saarend <sander@saarend.com>
Thu, 29 Jun 2023 02:53:15 +0000 (05:53 +0300)
committerGitHub <noreply@github.com>
Thu, 29 Jun 2023 02:53:15 +0000 (22:53 -0400)
Co-authored-by: SleeplessOne1917 <abias1122@gmail.com>
src/shared/components/common/image-upload-form.tsx
src/shared/components/common/markdown-textarea.tsx
src/shared/components/home/emojis-form.tsx
src/shared/components/post/post-form.tsx

index e8005ccc8d4bc04d216b4c6b428acc618bf9b4e0..854e7105adefe2444ef7ce9ed140669c4ad343d8 100644 (file)
@@ -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");
         }
index f7c4760aaa8da0592f8f3163e0923c328b9d1428..5623ace5dcf4bd78301d40dde90b1e2458286fa2 100644 (file)
@@ -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);
       }
index 149ff032468b7dfff405912e876344889882df84..4108e7a422ffa0c4a023eb252f57ea0afc30fb13 100644 (file)
@@ -508,6 +508,8 @@ export class EmojiForm extends Component<EmojiFormProps, EmojiFormState> {
             { 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");
         }
index 25a0fcc0889924a62a4b5d740c935859d30885a8..c29d3b1f448f0ea64cfdeb5eb0eac84578df353d 100644 (file)
@@ -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");
       }