Skip to content

Commit

Permalink
graceful error handling in earniings seasonal page
Browse files Browse the repository at this point in the history
  • Loading branch information
mnsrulz committed Nov 14, 2024
1 parent ab00c0a commit bf7aec8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/tradierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface Result {
type: string;
id: string;
tables: {
corporate_calendars: CorporateCalendar[];
corporate_calendars: CorporateCalendar[] | undefined;
};
}

Expand All @@ -50,6 +50,7 @@ interface CorporateCalendarResponse {
request: string;
type: string;
results: Result[];
error: string
}


Expand Down Expand Up @@ -169,7 +170,10 @@ export const getEarningDates = async (symbol: string) => {
'symbols': symbol
}
}).json<CorporateCalendarResponse[]>();
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)
Expand Down

0 comments on commit bf7aec8

Please sign in to comment.