From 33fd0e4ae26e4aaf7b5da9d4797ec0dc7330ebbe Mon Sep 17 00:00:00 2001 From: Garry Polley Date: Mon, 22 Apr 2019 12:43:03 -0500 Subject: [PATCH] fix: Do not log as errors below a 500 response (#1256) --- packages/errors/lib/error-handler.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/errors/lib/error-handler.js b/packages/errors/lib/error-handler.js index 4ff5bf7c87..9b16fe9923 100644 --- a/packages/errors/lib/error-handler.js +++ b/packages/errors/lib/error-handler.js @@ -23,9 +23,16 @@ module.exports = function (options = {}) { } return function (error, req, res, next) { + // Set the error code for HTTP processing semantics + error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500; + // Log the error if it didn't come from a service method call if (options.logger && typeof options.logger.error === 'function' && !res.hook) { - options.logger.error(error); + if (error.code >= 500) { + options.logger.error(error); + } else { + options.logger.info(error); + } } if (error.type !== 'FeathersError') { @@ -39,7 +46,6 @@ module.exports = function (options = {}) { } } - error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500; const formatter = {}; // If the developer passed a custom function for ALL html errors