From a9ff25c77170fdc4d3914d7ad86efbbd2a0a7585 Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frab1t@users.noreply.github.com> Date: Sat, 23 Feb 2019 23:21:39 +0100 Subject: [PATCH] add PositionNotFound --- api.js | 7 ++++++- templates.js | 6 ++++++ utils.js | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api.js b/api.js index a55dc8d..1f39493 100644 --- a/api.js +++ b/api.js @@ -53,7 +53,12 @@ function getInfoDevice(deviceId) { return res.json(); }) - .then(json => json) + .then((json) => { + if (!Object.prototype.hasOwnProperty.call(json, 'position')) { + throw new Error('PositionNotFound'); + } + return json; + }) .catch((err) => { logger.logError(err); return err; diff --git a/templates.js b/templates.js index 7be2656..3aacf5c 100644 --- a/templates.js +++ b/templates.js @@ -97,6 +97,11 @@ function devicesNotFound(data) { return msg; } +function positionNotFound() { + const msg = 'Position not found'; + return msg; +} + module.exports.unauthorizedUser = unauthorizedUser; module.exports.welcome = welcome; module.exports.help = help; @@ -107,3 +112,4 @@ module.exports.addDeviceHeader = addDeviceHeader; module.exports.addDeviceBody = addDeviceBody; module.exports.error = error; module.exports.devicesNotFound = devicesNotFound; +module.exports.positionNotFound = positionNotFound; diff --git a/utils.js b/utils.js index 60b7584..05d1363 100644 --- a/utils.js +++ b/utils.js @@ -8,6 +8,9 @@ function sendErrorMessage(error, msgBot) { case 'DeviceNotFound': msgBot.reply.text(templates.devicesNotFound(msgBot.text)); break; + case 'PositionNotFound': + msgBot.reply.text(templates.positionNotFound()); + break; default: msgBot.reply.text(templates.error()); }