mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-13 12:11:12 -06:00
getDistance() result usage processing, handle 'error' inner function result
Why was this not accounted for originally??
This commit is contained in:
@@ -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 });
|
||||||
|
|||||||
Reference in New Issue
Block a user