From da68c102cd3527c9b09d28e72718a2ebf8010304 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Fri, 11 Aug 2017 18:25:34 -0600 Subject: [PATCH 1/2] stop double printing uncaught error stacks --- boot/worker.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/boot/worker.js b/boot/worker.js index 3b1223a..78167de 100644 --- a/boot/worker.js +++ b/boot/worker.js @@ -149,9 +149,10 @@ module.exports.create = function () { process.on('unhandledRejection', function (err) { // this should always throw // (it means somewhere we're not using bluebird by accident) - console.error('[caught] [unhandledRejection]'); - console.error(Object.keys(err)); - console.error(err); + console.error('[caught unhandledRejection]:', err.message || ''); + Object.keys(err).forEach(function (key) { + console.log('\t'+key+': '+err[key]); + }); console.error(err.stack); }); process.on('rejectionHandled', function (msg) { From 08cb6c2d08b6a42b9572ec613e81a0480c9f4486 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Tue, 12 Sep 2017 11:55:47 -0600 Subject: [PATCH 2/2] made request error logging more DRY --- lib/common.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/common.js b/lib/common.js index 4c74c4a..701c0a3 100644 --- a/lib/common.js +++ b/lib/common.js @@ -1,20 +1,21 @@ 'use strict'; -module.exports.rejectableRequest = function rejectableRequest(req, res, promise, msg) { +function rejectableRequest(req, res, promise, msg) { return promise.error(function (err) { res.error(err); }).catch(function (err) { console.error('[ERROR] \'' + msg + '\''); - console.error(err.message); - console.error(err.stack); + // The stack contains the message as well, so no need to log the message when we log the stack + console.error(err.stack || err.message || JSON.stringify(err)); res.error(err); }); -}; +} +module.exports.rejectableRequest = rejectableRequest; module.exports.promisableRequest = module.exports.promiseRequest = function promiseRequest(req, res, promise, msg) { - return promise.then(function (result) { + promise = promise.then(function (result) { if (result._cache) { res.setHeader('Cache-Control', 'public, max-age=' + (result._cache / 1000)); res.setHeader('Expires', new Date(Date.now() + result._cache).toUTCString()); @@ -26,13 +27,7 @@ module.exports.promiseRequest = function promiseRequest(req, res, promise, msg) result = result._value; } res.send(result); - }).error(function (err) { - res.error(err); - }).catch(function (err) { - console.error('[ERROR] \'' + msg + '\''); - console.error(err.message); - console.error(err.stack); - - res.error(err); }); + + return rejectableRequest(req, res, promise, msg); };