export async function retrieveLocalisationInsert()

in lambda/rest-endpoints/src/curation.ts [94:127]


export async function retrieveLocalisationInsert(
	territory: string,
	date: Date,
): Promise<FeastAppContainer | undefined> {
	const today = formatDate(date, 'yyyy-MM-dd');

	try {
		const s3response = await s3Client.send(
			new GetObjectCommand({
				Bucket: getStaticBucketName(),
				Key: `dynamic/curation/${today}/${territory.toUpperCase()}.json`,
			}),
		);
		const rawData = await consumeReadable(
			s3response.Body as NodeJsRuntimeStreamingBlobTypes,
		);
		const rawJson = JSON.parse(rawData.toString()) as unknown;
		return FeastAppContainer.parse(rawJson);
	} catch (err) {
		if (err instanceof S3ServiceException) {
			//S3 often hides 'NotFound' behind 'AccessDenied' exceptions, so we treat them the same
			if (err.name == 'NotFound' || err.name == 'AccessDenied') {
				console.info(
					`No localisation found for ${territory} on ${date.toISOString()}`,
				);
				return undefined;
			} else {
				throw err;
			}
		} else {
			throw err;
		}
	}
}