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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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