Skip to content

Commit 2596450

Browse files
fix(POR-22666): handle platform FORM_RESPONSE errors in notification-center
Wrap notification fetch in try/catch so platform API errors like 'unable to perform action complete on FORM_RESPONSE' 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 2596450

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/app/notification-center/page.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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) 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)