async function getFeed()

in poller-lambdas/src/pollers/ap/apPoller.ts [123:146]


async function getFeed(
	url: string,
	apiKey: string,
): Promise<{ feed: FeedListData; timeReceived: Date }> {
	const headers: HeadersInit = {
		accept: 'application/json',
		'x-api-key': apiKey,
	};

	console.log(`polling for feed at ${url}`);

	const resp = await fetch(url, {
		headers,
	});
	const timeReceived = new Date();
	const feed = (await resp.json()) as unknown as FeedListData | FeedListError;
	if (isFeedListError(feed)) {
		throw new Error(feed.error?.message);
	}
	if (!isFeedListData(feed)) {
		throw new Error('Unexpected response from API');
	}
	return { feed, timeReceived };
}