Skip to content

Commit e3177d1

Browse files
authored
Update event fetching error handling
1 parent d6aa8df commit e3177d1

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

backend/src/data/eventData.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ export async function fetchEvents() {
5959
`https://graph.facebook.com/${FB_API_VERSION}/${process.env.FB_EVENT_PAGE_ID}/events?access_token=${process.env.FB_ACCESS_TOKEN}&fields=id,name,cover,place,start_time,end_time`
6060
);
6161

62-
if (!response || response.type === ResultType.Err) {
63-
console.log(`No events found...\n${response}`);
64-
return [];
62+
if (!response.ok) {
63+
throw new Error(JSON.stringify(response.json()));
6564
}
6665
const res: FacebookEventsResponse = await response.json();
6766

@@ -85,15 +84,10 @@ export async function fetchEvent(id: string) {
8584
`https://graph.facebook.com/${FB_API_VERSION}/${id}?access_token=${process.env.FB_ACCESS_TOKEN}&fields=id,name,cover,place,start_time,end_time`
8685
);
8786

88-
const res: Result<FacebookEvent, FacebookError> = await response.json();
89-
90-
if (!res || res.type === ResultType.Err) {
91-
throw new Error(
92-
`Couldn't fetch details for event ${id}\n${inspect(
93-
Object.getOwnPropertyDescriptor(res, "error")?.value
94-
)}`
95-
);
87+
if (!response.ok) {
88+
throw new Error(`Couldn't fetch details for event ${id}\n${JSON.stringify(response.json())}`);
9689
}
90+
const res: Result<FacebookEvent, FacebookError> = await response.json();
9791

9892
return new EventInfo(
9993
res.value.id,

0 commit comments

Comments
 (0)