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); const key = getKey(matching.name, now);
// Check if I am in range of the center // 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 // TODO: Properly draw from environment MAX_DISTANCE
if (distanceToCenter > 280) const distance = distanceResult.value;
if (distance > 280)
return { return {
status: 'out-of-range', status: 'out-of-range',
identifier: { name: matching.name, key } identifier: { name: matching.name, key }
@@ -87,6 +93,8 @@ export default async function handler(
logger.info('Cron evaluated.', { result }); logger.info('Cron evaluated.', { result });
if (result.status === 'error') res.status(500).json({ status: 'error' });
else
res res
.status(200) .status(200)
.json({ status: result.status, identifier: result.identifier }); .json({ status: result.status, identifier: result.identifier });