From c8a978b23b524a79cfc8ce78e6354d0798796947 Mon Sep 17 00:00:00 2001 From: SandipBajracharya Date: Fri, 19 Sep 2025 14:12:30 +0545 Subject: [PATCH] fix(OUT-2328): triage: cannot read properties of undefined(reading 'contentType') - [x] implement size validation before upload and error toast if validation fails - [x] error toast if invoked variable is undefined Note: Upon checking the log, the upload process was returning 413 (file too large). Due to this the function handling the upload was not returning anything at all. That basically makes the invoking variable undefined. --- .../tiptap/floatingMenu/floatingMenuSuggestion.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/tiptap/floatingMenu/floatingMenuSuggestion.tsx b/src/components/tiptap/floatingMenu/floatingMenuSuggestion.tsx index c97d185..03e81fb 100644 --- a/src/components/tiptap/floatingMenu/floatingMenuSuggestion.tsx +++ b/src/components/tiptap/floatingMenu/floatingMenuSuggestion.tsx @@ -5,6 +5,8 @@ import { FloatingMenu } from './FloatingMenu' import { TiptapEditorUtils } from '@/utils/tiptapEditorUtils' import { ImagePickerUtils } from '@/utils/imagePickerUtils' import { handleBannerImageUpload } from '@/utils/handleBannerImageUpload' +import { calculateFileSize } from '@/utils/calculateFileSize' +import toast from 'react-hot-toast' export const floatingMenuSuggestion = { items: ({ query }: any) => { @@ -76,7 +78,16 @@ export const floatingMenuSuggestion = { 'token', ) if (file && token) { + // file size validation + const size = calculateFileSize(file) + if (size > 4.5) { + toast.error('File size is too large!') + return + } + const data = await handleBannerImageUpload(file, token) + if (!data) toast.error('Something went wrong while uploading file') + if (data.contentType === 'application/pdf') { tiptapEditorUtils.insertPdf(data.filename, data.url) } else {