1
0
mirror of https://github.com/franjsco/trackmyd-bot synced 2025-06-05 22:19:29 +02:00

fix error handling

This commit is contained in:
Francesco Esposito
2019-03-04 20:07:46 +01:00
parent ed310c4e4b
commit ceaeadb84b
2 changed files with 4 additions and 19 deletions

8
api.js
View File

@@ -27,7 +27,7 @@ function getDevices() {
.then(json => json)
.catch((err) => {
logger.logError(err);
return err;
throw err;
});
}
@@ -61,7 +61,7 @@ function getInfoDevice(deviceId) {
})
.catch((err) => {
logger.logError(err);
return err;
throw err;
});
}
@@ -91,7 +91,7 @@ function addDevice(name) {
.then(json => json)
.catch((err) => {
logger.logError(err);
return err;
throw err;
});
}
@@ -117,7 +117,7 @@ function removeDevice(deviceId) {
.then(json => json)
.catch((err) => {
logger.logError(err);
return err;
throw err;
});
}

View File

@@ -37,9 +37,6 @@ bot.on('/list', (msg) => {
api.getDevices()
.then((res) => {
if (res instanceof Error) {
throw res;
}
res.forEach((elem) => {
bot.sendMessage(msg.from.id, templates.deviceList(elem), { parseMode: 'Markdown' });
});
@@ -56,10 +53,6 @@ bot.on('/position', (msg) => {
api.getDevices()
.then((res) => {
if (res instanceof Error) {
throw res;
}
const devices = [];
res.forEach((device) => {
devices.push(device.name);
@@ -80,10 +73,6 @@ bot.on('ask.devicePosition', (msg) => {
api.getInfoDevice(msg.text)
.then((res) => {
if (res instanceof Error) {
throw res;
}
bot.sendLocation(msg.from.id, [res.position.latitude, res.position.longtitude]);
bot.sendMessage(msg.from.id, templates.position(res), { parseMode: 'Markdown' });
})
@@ -106,10 +95,6 @@ bot.on('ask.addDevice', (msg) => {
api.addDevice(msg.text)
.then((res) => {
if (res instanceof Error) {
throw res;
}
bot.sendMessage(msg.from.id, templates.addDeviceURL(res));
bot.sendMessage(msg.from.id, templates.addDeviceHeader());
bot.sendMessage(msg.from.id, templates.addDeviceBody());