Slack messaging #169
4 changed files with 20 additions and 9 deletions
|
@ -1,9 +1,20 @@
|
|||
const logger = require('winston');
|
||||
const { postToStats } = require('../controllers/statsController.js');
|
||||
|
||||
function useObjectPropertiesIfNoKeys (err) {
|
||||
if (Object.keys(err).length === 0) {
|
||||
let newErrorObject = {};
|
||||
Object.getOwnPropertyNames(err).forEach((key) => {
|
||||
for errors created by node (e.g. for errors created by node (e.g. `new Error('error message')`) the stack and message are non-enumerable
|
||||
newErrorObject[key] = err[key];
|
||||
});
|
||||
return newErrorObject;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
handleRequestError (action, originalUrl, ip, error, res) {
|
||||
logger.error('Request Error:', error.message);
|
||||
logger.error('Request Error:', useObjectPropertiesIfNoKeys(error));
|
||||
postToStats(action, originalUrl, ip, null, null, error);
|
||||
if (error.response) {
|
||||
res.status(error.response.status).send(error.response.data.error.message);
|
||||
|
@ -16,7 +27,7 @@ module.exports = {
|
|||
}
|
||||
},
|
||||
handlePublishError (error) {
|
||||
logger.error('Publish Error:', error.message);
|
||||
logger.error('Publish Error:', useObjectPropertiesIfNoKeys(error));
|
||||
if (error.code === 'ECONNREFUSED') {
|
||||
return 'Connection refused. The daemon may not be running.';
|
||||
} else if (error.response.data.error) {
|
||||
|
|
|
@ -115,7 +115,7 @@ module.exports = {
|
|||
}
|
||||
})
|
||||
.catch(error => {
|
||||
logger.error('Lbrynet Error:', error.message);
|
||||
logger.error('Lbrynet Error:', error);
|
||||
resolve('/home/lbry/Downloads/');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -52,7 +52,7 @@ function getLongClaimIdFromShortClaimId (name, shortId) {
|
|||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
return reject(new Error('That is an invalid Short Claim Id'));
|
||||
throw new Error('That is an invalid Short Claim Id');
|
||||
default: // note results must be sorted
|
||||
return resolve(result[0].claimId);
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ db['getShortClaimIdFromLongClaimId'] = (claimId, claimName) => {
|
|||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
return reject(new Error('That is an invalid claim name'));
|
||||
throw new Error('That is an invalid claim name');
|
||||
default:
|
||||
return resolve(sortResult(result, claimId));
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ db['getShortChannelIdFromLongChannelId'] = (channelName, longChannelId) => {
|
|||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
return reject(new Error('That is an invalid channel name'));
|
||||
throw new Error('That is an invalid channel name');
|
||||
default:
|
||||
return resolve(sortResult(result, longChannelId));
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ db['resolveClaim'] = (name, claimId) => {
|
|||
case 1:
|
||||
return resolve(result[0]);
|
||||
default:
|
||||
return new Error('more than one entry matches that name and claimID');
|
||||
throw new Error('more than one entry matches that name and claimID');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -255,7 +255,7 @@ db['getClaimIdByLongChannelId'] = (channelId, claimName) => {
|
|||
.then(result => {
|
||||
switch (result.length) {
|
||||
case 0:
|
||||
return reject(new Error('There is no such claim for that channel'));
|
||||
throw new Error('There is no such claim for that channel');
|
||||
default:
|
||||
return resolve(result[0].claimId);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"socketio-file-upload": "^0.6.0",
|
||||
"universal-analytics": "^0.4.13",
|
||||
"winston": "^2.3.1",
|
||||
"winston-slack-webhook": "^0.1.5"
|
||||
"winston-slack-webhook": "billbitt/winston-slack-webhook"
|
||||
},
|
||||
should this be billbitt? should this be billbitt?
I made my own fork to fix an issue with the package, and submitted a PR to the main package. The PR was accepted, so will update this to point to main package in next update. I made my own fork to fix an issue with the package, and submitted a PR to the main package. The PR was accepted, so will update this to point to main package in next update.
|
||||
"devDependencies": {
|
||||
"eslint": "3.19.0",
|
||||
|
|
Loading…
Reference in a new issue
When is there a non-enumerable property being passed that this is required?