getDistance() result usage processing, handle 'error' inner function result

Why was this not accounted for originally??
This commit is contained in:
2023-09-05 12:29:44 -05:00
parent 81b781aea1
commit b7d301f8fe

View File

@@ -53,9 +53,15 @@ export default async function handler(
const key = getKey(matching.name, now);
// Check if I am in range of the center
const distanceToCenter = await getDistance();
const distanceResult = await getDistance();
if (distanceResult.isErr) {
logger.error(distanceResult.error);
return { status: 'error' };
}
// TODO: Properly draw from environment MAX_DISTANCE
if (distanceToCenter > 280)
const distance = distanceResult.value;
if (distance > 280)
return {
status: 'out-of-range',
identifier: { name: matching.name, key }
@@ -87,9 +93,11 @@ export default async function handler(
logger.info('Cron evaluated.', { result });
res
.status(200)
.json({ status: result.status, identifier: result.identifier });
if (result.status === 'error') res.status(500).json({ status: 'error' });
else
res
.status(200)
.json({ status: result.status, identifier: result.identifier });
} catch (e) {
logger.error(e);
res.status(500).json({ status: 'error' });