From bf7aec8a1a4b041944552df76dfc6f9114267f15 Mon Sep 17 00:00:00 2001 From: mnsrulz Date: Wed, 13 Nov 2024 20:18:32 -0500 Subject: [PATCH] graceful error handling in earniings seasonal page --- src/lib/tradierService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/tradierService.ts b/src/lib/tradierService.ts index 2775c23..d70f87c 100644 --- a/src/lib/tradierService.ts +++ b/src/lib/tradierService.ts @@ -36,7 +36,7 @@ interface Result { type: string; id: string; tables: { - corporate_calendars: CorporateCalendar[]; + corporate_calendars: CorporateCalendar[] | undefined; }; } @@ -50,6 +50,7 @@ interface CorporateCalendarResponse { request: string; type: string; results: Result[]; + error: string } @@ -169,7 +170,10 @@ export const getEarningDates = async (symbol: string) => { 'symbols': symbol } }).json(); - const earnings = calendar[0].results.flatMap(j => j.tables.corporate_calendars) + if(calendar[0].error) { + return []; + } + const earnings = calendar[0].results.flatMap(j => j.tables.corporate_calendars || []) // .filter(j => j != null) // .filter(j => j != undefined) //.filter(j => j.event_type == 14)