fix some 500 errors and remove unnecessary console.log calls

This commit is contained in:
Akinwale Ariwodola 2019-04-12 18:01:07 +02:00
parent a5d9ce9bec
commit 8ca114369d

30
app.js
View file

@ -104,7 +104,6 @@ const retrieveUnreadMessages = (accessToken, callback) => {
const url = util.format('%s/message/unread?limit=100', baseUrl); const url = util.format('%s/message/unread?limit=100', baseUrl);
request.get({ url: url, headers: { 'User-Agent': 'lbryian/1.0.0 Node.js (by /u/lbryian)', 'Authorization': 'Bearer ' + accessToken } }, (err, res, body) => { request.get({ url: url, headers: { 'User-Agent': 'lbryian/1.0.0 Node.js (by /u/lbryian)', 'Authorization': 'Bearer ' + accessToken } }, (err, res, body) => {
if (err) { if (err) {
console.log(err);
return callback(err); return callback(err);
} }
@ -119,6 +118,8 @@ const retrieveUnreadMessages = (accessToken, callback) => {
return callback(new Error(response.message)); return callback(new Error(response.message));
} }
console.log(`Got ${response.data.children.length} unread messages.`);
return callback(null, response.data.children); return callback(null, response.data.children);
}); });
}; };
@ -140,7 +141,6 @@ const createOrGetUserId = (username, callback) => {
if (userId === 0) { if (userId === 0) {
return db.query('INSERT INTO Users (Username, Created) VALUES (?, UTC_TIMESTAMP())', [username], (err, res) => { return db.query('INSERT INTO Users (Username, Created) VALUES (?, UTC_TIMESTAMP())', [username], (err, res) => {
if (err) { if (err) {
console.log(err);
return cb(err, null); return cb(err, null);
} }
@ -310,7 +310,6 @@ const sendTip = (sender, recipient, amount, tipdata, callback) => {
], cb); ], cb);
}, },
(res, fields, cb) => { (res, fields, cb) => {
console.log('Inserting tip.');
// save the tip information // save the tip information
db.query( ['INSERT INTO Tips (MessageId, SenderId, RecipientId, Amount, AmountUsd, ParsedAmount, Created) ', db.query( ['INSERT INTO Tips (MessageId, SenderId, RecipientId, Amount, AmountUsd, ParsedAmount, Created) ',
'VALUES (?, ?, ?, ?, ?, ?, UTC_TIMESTAMP())'].join(''), 'VALUES (?, ?, ?, ?, ?, ?, UTC_TIMESTAMP())'].join(''),
@ -344,7 +343,6 @@ const sendTip = (sender, recipient, amount, tipdata, callback) => {
} }
], (err) => { ], (err) => {
if (err) { if (err) {
console.log(err);
return db.rollback(() => { return db.rollback(() => {
callback(err, null); callback(err, null);
}); });
@ -426,6 +424,7 @@ const markMessageRead = (messageFullId, callback) => {
const url = `${baseUrl}/api/read_message`; const url = `${baseUrl}/api/read_message`;
request.post({ url, form: { id: messageFullId }, headers: { 'User-Agent': config.userAgent, 'Authorization': 'Bearer ' + globalAccessToken } }, (err, res, body) => { request.post({ url, form: { id: messageFullId }, headers: { 'User-Agent': config.userAgent, 'Authorization': 'Bearer ' + globalAccessToken } }, (err, res, body) => {
if (err) { if (err) {
console.log(err);
return callback(err, null); return callback(err, null);
} }
@ -694,7 +693,13 @@ const doGild = function(message, callback) {
return cb(null, null); return cb(null, null);
} }
], callback); ], (err) => {
if (err) {
callback(err, null);
}
markMessageRead(message.data.name, callback);
});
}; };
const doSendTip = (body, message, callback) => { const doSendTip = (body, message, callback) => {
@ -779,10 +784,11 @@ const doSendTip = (body, message, callback) => {
if (data) { if (data) {
return sendTip(data.sender, data.recipient, data.amountLbc, data, cb); return sendTip(data.sender, data.recipient, data.amountLbc, data, cb);
} }
return cb(null, null);
} }
], callback); ], (err) => {
if (err) { callback(err, null); }
markMessageRead(message.data.name, callback);
});
} }
// not a valid or recognised message, simply mark the message as read // not a valid or recognised message, simply mark the message as read
@ -807,7 +813,6 @@ const doSendBalance = (message, callback) => {
} }
], (err) => { ], (err) => {
if (err) { if (err) {
console.log(err);
return callback(err, null); return callback(err, null);
} }
@ -896,7 +901,6 @@ const doWithdrawal = (amount, address, message, callback) => {
} }
], (err) => { ], (err) => {
if (err) { if (err) {
console.log(err);
return db.rollback(() => { return db.rollback(() => {
callback(err, null); callback(err, null);
}); });
@ -940,6 +944,7 @@ const doSendDepositAddress = (message, callback) => {
// withdraw (PM): withdraw <amount> <address> // withdraw (PM): withdraw <amount> <address>
const processMessage = function(message, callback) { const processMessage = function(message, callback) {
if (!message.kind || !message.data) { if (!message.kind || !message.data) {
//console.log('Invalid message encountered.');
return callback(new Error('Invalid message specified for processing.')); return callback(new Error('Invalid message specified for processing.'));
} }
@ -959,7 +964,8 @@ const processMessage = function(message, callback) {
if (parts.length !== 3 || if (parts.length !== 3 ||
parts[0].toLowerCase() !== 'withdraw') { parts[0].toLowerCase() !== 'withdraw') {
// invalid message, ignore // invalid message, ignore
return callback(null, null); //console.log("Invalid Message=" + body);
return markMessageRead(message.data.name, callback);
} }
const amount = parseFloat(parts[1]); const amount = parseFloat(parts[1]);
@ -990,7 +996,7 @@ const processMessage = function(message, callback) {
return doWithdrawal(amount, address, message, callback); return doWithdrawal(amount, address, message, callback);
} }
return callback(null, null); return markMessageRead(message.data.name, callback);
} }
if (message.kind === commentKind) { if (message.kind === commentKind) {