use telegram bot for error messages

This commit is contained in:
2020-05-14 12:21:30 +02:00
parent ac27d775db
commit 2584c21239
2 changed files with 5 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ const TelegramBot = require('node-telegram-bot-api');
const simCo = require('./simco-credentials'); const simCo = require('./simco-credentials');
const tgInfo = require('./telegram-credentials'); const tgInfo = require('./telegram-credentials');
if (!simCo.cookie || !tgInfo.token || !tgInfo.infoChat) { if (!simCo.cookie || !tgInfo.token || !tgInfo.infoChat || !tgInfo.debugChat) {
console.error("ERR: credentials not set.") console.error("ERR: credentials not set.")
return; return;
} }
@@ -24,6 +24,7 @@ const bondFetchProcess = async (url) => {
}); });
var t1 = await BondData.json(); var t1 = await BondData.json();
} catch (e) { } catch (e) {
tgBot.sendMessage(tgInfo.debugChat, `ERROR: fetching bonds:\n${e}`);
console.error(e); console.error(e);
} }
for (let data in t1) { for (let data in t1) {

View File

@@ -63,6 +63,7 @@ const getFullData = async url => {
}) })
} }
} else { } else {
tgBot.sendMessage(tgInfo.debugChat, `ERROR: fetching market:\nStatus Code: ${marketData.status}`);
throw ("fetch returned status code " + marketData.status); throw ("fetch returned status code " + marketData.status);
} }
} }
@@ -84,6 +85,7 @@ const storeFullData = async marketData => {
const querystring = `INSERT INTO marketv2 (kind,price,time, quality) VALUES (${kind},${price},${storedate}, ${quality})` const querystring = `INSERT INTO marketv2 (kind,price,time, quality) VALUES (${kind},${price},${storedate}, ${quality})`
connection.query(querystring, function (error, results, fields) { connection.query(querystring, function (error, results, fields) {
if (error) { if (error) {
tgBot.sendMessage(tgInfo.debugChat, `ERROR: fetching market - database error:\n${error}`);
return connection.rollback(function () { return connection.rollback(function () {
throw error; throw error;
}); });
@@ -100,6 +102,7 @@ const storeFullData = async marketData => {
const querystring = `INSERT INTO marketcap (kind,quality,price,amount,time) VALUES (${kind},${quality},${price},${amount},${storedate})`; const querystring = `INSERT INTO marketcap (kind,quality,price,amount,time) VALUES (${kind},${quality},${price},${amount},${storedate})`;
connection.query(querystring, function (error, results, fields) { connection.query(querystring, function (error, results, fields) {
if (error) { if (error) {
tgBot.sendMessage(tgInfo.debugChat, `ERROR: fetching market - database error:\n${error}`);
return connection.rollback(function () { return connection.rollback(function () {
throw error; throw error;
}); });