diff --git a/controllers/analyticsController.js b/controllers/analyticsController.js index 1497b411..0aee6bc4 100644 --- a/controllers/analyticsController.js +++ b/controllers/analyticsController.js @@ -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; diff --git a/controllers/publishController.js b/controllers/publishController.js index e6474276..ccc8967f 100644 --- a/controllers/publishController.js +++ b/controllers/publishController.js @@ -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 diff --git a/controllers/serveController.js b/controllers/serveController.js index 4017bd33..4b0423eb 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -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); }); }); diff --git a/helpers/libraries/analytics.js b/helpers/libraries/analytics.js index 509d7362..1a42a2f5 100644 --- a/helpers/libraries/analytics.js +++ b/helpers/libraries/analytics.js @@ -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, diff --git a/helpers/libraries/errorHandlers.js b/helpers/libraries/errorHandlers.js index 172ee912..09a18c81 100644 --- a/helpers/libraries/errorHandlers.js +++ b/helpers/libraries/errorHandlers.js @@ -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; } }, diff --git a/models/analytics.js b/models/analytics.js index fca25233..9bb80378 100644 --- a/models/analytics.js +++ b/models/analytics.js @@ -13,10 +13,12 @@ module.exports = (sequelize, { STRING }) => { ipAddress: { type : STRING, allowNull: true, + default : null, }, result: { type : STRING, - allowNull: false, + allowNull: true, + default : null, }, }, { diff --git a/routes/serve-routes.js b/routes/serve-routes.js index bfce7db1..4a57bff0 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -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); }); diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js index 063f5357..569a4f08 100644 --- a/routes/sockets-routes.js +++ b/routes/sockets-routes.js @@ -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`);