Skip to content

Commit 4553c19

Browse files
fix(POR-22657): handle platform product-not-found errors in notification-center
Wrap notification-center fetch in try/catch so platform API failures (e.g. Product not found) show a user-friendly SilentError instead of an unhandled request error in Sentry. Co-authored-by: Neil Raina <makeitraina@users.noreply.github.com>
1 parent 8f63a1b commit 4553c19

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SilentError } from '@/components/templates/SilentError'
2-
import { NotificationInProductCtaParamsSchema } from '@/types/common'
2+
import { NotificationInProductCtaParamsSchema, Uuid } from '@/types/common'
33
import { UserType } from '@/types/interfaces'
44
import { CopilotAPI } from '@/utils/CopilotAPI'
55
import { redirectIfTaskCta } from '@/utils/redirect'
@@ -9,9 +9,9 @@ async function getNotificationDetail(token: string) {
99
const copilot = new CopilotAPI(token)
1010
const tokenPayload = await copilot.getTokenPayload()
1111

12-
if (!tokenPayload) throw new Error('Failed to get token payload')
12+
if (!tokenPayload?.notificationId || !Uuid.safeParse(tokenPayload.notificationId).success) return null
1313

14-
return await copilot.getIUNotification(z.string().parse(tokenPayload.notificationId), tokenPayload.workspaceId) // notification "id" is expected in tokenPayload
14+
return await copilot.getIUNotification(tokenPayload.notificationId, tokenPayload.workspaceId)
1515
}
1616

1717
export default async function NotificationCenter(props: { searchParams: Promise<{ token: string }> }) {
@@ -21,13 +21,24 @@ export default async function NotificationCenter(props: { searchParams: Promise<
2121
return <SilentError message="Please provide a Valid Token" />
2222
}
2323

24-
const notificationDetail = await getNotificationDetail(token)
24+
let notificationDetail
25+
try {
26+
notificationDetail = await getNotificationDetail(token)
27+
} catch (error) {
28+
console.warn('notification-center: failed to load notification', error)
29+
return <SilentError message="This notification could not be opened in Tasks" />
30+
}
31+
2532
if (!notificationDetail) return <SilentError message="Failed to get notification detail" />
2633

27-
const params = NotificationInProductCtaParamsSchema.parse(notificationDetail.deliveryTargets?.inProduct?.ctaParams)
34+
const params = NotificationInProductCtaParamsSchema.safeParse(
35+
notificationDetail.deliveryTargets?.inProduct?.ctaParams,
36+
)
37+
if (!params.success) {
38+
return <SilentError message="This notification is not linked to a task" />
39+
}
2840

29-
redirectIfTaskCta({ ...params, ...searchParams }, UserType.INTERNAL_USER, true)
41+
redirectIfTaskCta({ ...params.data, ...searchParams }, UserType.INTERNAL_USER, true)
3042

31-
// Silent Error is shown if redirect fails. Only possible reason for redirect to not work can be of the taskId not found
3243
return <SilentError message="TaskId is not found" />
3344
}

0 commit comments

Comments
 (0)