update error handler to convert props to keys

This commit is contained in:
bill bittner 2017-09-14 11:34:13 -07:00
parent 456c2dc831
commit f53ca8d958
4 changed files with 20 additions and 9 deletions

View file

@ -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) => {
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) {

View file

@ -115,7 +115,7 @@ module.exports = {
}
})
.catch(error => {
logger.error('Lbrynet Error:', error.message);
logger.error('Lbrynet Error:', error);
resolve('/home/lbry/Downloads/');
});
});

View file

@ -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);
}

View file

@ -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"
},
"devDependencies": {
"eslint": "3.19.0",