add PositionNotFound

This commit is contained in:
Francesco Esposito 2019-02-23 23:21:39 +01:00
parent 059b5d515a
commit a9ff25c771
3 changed files with 15 additions and 1 deletions

7
api.js
View File

@ -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;

View File

@ -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;

View File

@ -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());
}