Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions backend/src/data/eventData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export async function fetchEvents() {
`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`
);

if (!response || response.type === ResultType.Err) {
console.log(`No events found...\n${response}`);
return [];
if (!response.ok) {
throw new Error(JSON.stringify(response.json()));

}
const res: FacebookEventsResponse = await response.json();

Expand All @@ -85,22 +85,17 @@ export async function fetchEvent(id: string) {
`https://graph.facebook.com/${FB_API_VERSION}/${id}?access_token=${process.env.FB_ACCESS_TOKEN}&fields=id,name,cover,place,start_time,end_time`
);

const res: Result<FacebookEvent, FacebookError> = await response.json();

if (!res || res.type === ResultType.Err) {
throw new Error(
`Couldn't fetch details for event ${id}\n${inspect(
Object.getOwnPropertyDescriptor(res, "error")?.value
)}`
);
if (!response.ok) {
throw new Error(`Couldn't fetch details for event ${id}\n${JSON.stringify(response.json())}`);
}
const res: FacebookEvent = await response.json();

return new EventInfo(
res.value.id,
res.value.name,
res.value.start_time,
res.value.end_time,
res.value.place?.name ?? DEFAULT_EVENT_LOCATION,
res.value.cover?.source ?? DEFAULT_EVENT_IMAGE
res.id,
res.name,
res.start_time,
res.end_time,
res.place?.name ?? DEFAULT_EVENT_LOCATION,
res.cover?.source ?? DEFAULT_EVENT_IMAGE
);
}
2 changes: 1 addition & 1 deletion backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dotenv.config();
(async () => {
try {
const events = await fetchEvents();
eventInfoMutex.runExclusive(() => eventInfo.concat(events));
eventInfoMutex.runExclusive(() => eventInfo.push(...events));
console.log("Events fetched successfully");
} catch (error) {
// do we ungracefully bail out here???
Expand Down
Loading