Skip to content

Commit 81e2dbd

Browse files
committed
Add try catch.
1 parent a8c367d commit 81e2dbd

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

iot-devices/lib/ngsi-ld.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,24 @@ function listEntities(opts, headers = {}) {
5252
});
5353
}
5454

55-
exports.findNeighbour = async function (lat, lng, type) {
55+
exports.findNeighbour = async function (lat, lng, type, previous) {
5656
const headers = setHeaders(null, LinkHeader);
57-
const entities = await listEntities(
58-
{
59-
type,
60-
pick: 'id',
61-
limit: 2,
62-
geometry: 'Point',
63-
coordinates: `[${lat},${lng}]`,
64-
georel: 'near;maxDistance==8000',
65-
},
66-
headers
67-
);
68-
return entities[1].id;
57+
try {
58+
const entities = await listEntities(
59+
{
60+
type,
61+
pick: 'id',
62+
limit: 2,
63+
geometry: 'Point',
64+
coordinates: `[${lat},${lng}]`,
65+
georel: 'near;maxDistance==8000',
66+
},
67+
headers
68+
);
69+
return entities[1].id;
70+
} catch (error) {
71+
return previous;
72+
}
6973
};
7074

7175
exports.findTargetInField = async function (type, locatedAt) {

iot-devices/models/devices.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ function sendAnimalCollarReadings() {
387387
state.near = await NgsiLd.findNeighbour(
388388
coords[0],
389389
coords[1],
390-
'Animal'
390+
'Animal',
391+
state.near
391392
);
392393
}
393394
setDeviceState(deviceId, toUltraLight(state), isSensor);

0 commit comments

Comments
 (0)