From 49b22eeec6c15ca5e6759dd021140295f2071eb4 Mon Sep 17 00:00:00 2001 From: bosiraphael <71827178+bosiraphael@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:33:48 +0100 Subject: [PATCH] Catch graphql errors (#3634) * Catch graphql errors * update according to comment --- .../emails/components/EmailThreads.tsx | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx b/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx index 0b4bedfc22..ffe468a54f 100644 --- a/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx +++ b/packages/twenty-front/src/modules/activities/emails/components/EmailThreads.tsx @@ -12,6 +12,7 @@ import { H1Title, H1TitleFontColor, } from '@/ui/display/typography/components/H1Title'; +import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; import { Card } from '@/ui/layout/card/components/Card'; import { Section } from '@/ui/layout/section/components/Section'; import { TimelineThread } from '~/generated/graphql'; @@ -39,6 +40,8 @@ export const EmailThreads = ({ }) => { const { openEmailThread } = useEmailThread(); + const { enqueueSnackBar } = useSnackBar(); + const threadQuery = entity.targetObjectNameSingular === CoreObjectNameSingular.Person ? getTimelineThreadsFromPersonId @@ -56,16 +59,22 @@ export const EmailThreads = ({ variables: threadQueryVariables, }); + if (threads.error) { + enqueueSnackBar(threads.error.message || 'Error loading email threads', { + variant: 'error', + }); + } + if (threads.loading) { return; } const timelineThreads: TimelineThread[] = - threads.data[ + threads?.data?.[ entity.targetObjectNameSingular === CoreObjectNameSingular.Person ? 'getTimelineThreadsFromPersonId' : 'getTimelineThreadsFromCompanyId' - ]; + ] ?? []; return ( @@ -80,15 +89,14 @@ export const EmailThreads = ({ fontColor={H1TitleFontColor.Primary} /> - {timelineThreads && - timelineThreads.map((thread: TimelineThread, index: number) => ( - openEmailThread(thread)} - /> - ))} + {timelineThreads.map((thread: TimelineThread, index: number) => ( + openEmailThread(thread)} + /> + ))}