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:
8
api.js
8
api.js
@@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
|
15
server.js
15
server.js
@@ -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());
|
||||
|
Reference in New Issue
Block a user