updated error handling

This commit is contained in:
bill bittner 2017-06-27 21:32:05 -07:00
parent 8da934af84
commit 7efce7739b
8 changed files with 18 additions and 6 deletions

View file

@ -3,6 +3,7 @@ const db = require('../models');
module.exports = {
getAnalyticsSummary: () => {
logger.debug('retrieving analytics');
const deferred = new Promise((resolve, reject) => {
// get the raw analytics data
db.Analytics
@ -15,7 +16,6 @@ module.exports = {
let totalCount = 0;
let totalSuccess = 0;
let totalFailure = 0;
// sumarise the data
for (let i = 0; i < data.length; i++) {
let key = data[i].action + data[i].url;

View file

@ -50,7 +50,6 @@ module.exports = {
});
})
.catch(error => {
logger.error(`Error publishing ${fileName}`, error);
// delete the local file
publishHelpers.deleteTemporaryFile(publishParams.file_path);
// reject the promise

View file

@ -107,6 +107,7 @@ module.exports = {
// 1. get the top free, public claims
getAllFreePublicClaims(claimName)
.then(freePublicClaimList => {
console.log('I got here!');
const name = freePublicClaimList[0].name;
const claimId = freePublicClaimList[0].claim_id;
const uri = `${name}#${claimId}`;
@ -133,6 +134,7 @@ module.exports = {
});
})
.catch(error => {
console.log('I got here too!');
reject(error);
});
});

View file

@ -2,6 +2,10 @@ const db = require('../../models');
const logger = require('winston');
function createAnalyticsRecord (action, url, ipAddress, result) {
logger.silly('creating record for analytics');
if (result && (typeof result !== 'string')) {
result = result.toString();
}
db.Analytics.create({
action,
url,

View file

@ -14,12 +14,14 @@ module.exports = {
}
},
handlePublishError (error) {
logger.error('Publish Error >>', error);
if (error.code === 'ECONNREFUSED') {
logger.error('Publish Error:', 'Connection refused. The daemon may not be running.');
return 'Connection refused. The daemon may not be running.';
} else if (error.response.data.error) {
return error.response.data.error;
logger.error('Publish Error:', error.response.data.error);
return error.response.data.error.message;
} else {
logger.error('Unhandled Publish Error:', error);
return error;
}
},

View file

@ -13,10 +13,12 @@ module.exports = (sequelize, { STRING }) => {
ipAddress: {
type : STRING,
allowNull: true,
default : null,
},
result: {
type : STRING,
allowNull: false,
allowNull: true,
default : null,
},
},
{

View file

@ -55,10 +55,12 @@ module.exports = (app) => {
serveController
.getClaimByName(params.name)
.then(fileInfo => {
console.log('hi there!');
postRequestAnalytics(originalUrl, ip, 'success');
serveFile(fileInfo, res);
})
.catch(error => {
console.log('hi there too!');
postRequestAnalytics(originalUrl, ip, error);
errorHandlers.handleRequestError(error, res);
});

View file

@ -43,8 +43,9 @@ module.exports = (app, siofu, hostedContentPath) => {
socket.emit('publish-complete', { name: publishParams.name, result });
})
.catch(error => {
error = errorHandlers.handlePublishError(error);
postPublishAnalytics('spee.ch/', null, error);
socket.emit('publish-failure', errorHandlers.handlePublishError(error));
socket.emit('publish-failure', error);
});
} else {
logger.error(`An error occurred in uploading the client's file`);