Skip to content

Commit 65755c0

Browse files
fix(POR-22649): handle app-setup entity errors in notification-center
Add defensive error handling on /notification-center so platform API failures (e.g. "No entity type for app-setup found") show a user-friendly SilentError instead of an unhandled Next.js request error in Sentry. Co-authored-by: Neil Raina <makeitraina@users.noreply.github.com>
1 parent 8f63a1b commit 65755c0

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎src/app/notification-center/page.tsx‎

Lines changed: 15 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,22 @@ 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(notificationDetail.deliveryTargets?.inProduct?.ctaParams)
35+
if (!params.success) {
36+
return <SilentError message="This notification is not linked to a task" />
37+
}
2838

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

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

0 commit comments

Comments
 (0)