diff --git a/backend/src/data/eventData.ts b/backend/src/data/eventData.ts index b188863..0ca44a8 100644 --- a/backend/src/data/eventData.ts +++ b/backend/src/data/eventData.ts @@ -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(); @@ -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 = 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 ); } diff --git a/backend/src/index.ts b/backend/src/index.ts index e3a7ae2..fd9c8bd 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -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???