From bf2a29d294c9cb9d76305fed4c6f7a24c40e9a7f Mon Sep 17 00:00:00 2001 From: Garry Polley Date: Tue, 19 Mar 2019 11:00:43 -0500 Subject: [PATCH 1/2] Do not log as errors below a 500 response API error message logs should only contain errors that would be worth alerting on. If the server response is below 500 there isn't a server side error, therefore the service should not log as an error. --- 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..062657c663 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 From 0a48d61d4effb3107cc7412758b639e5f5806874 Mon Sep 17 00:00:00 2001 From: Garry Polley Date: Mon, 15 Apr 2019 10:55:09 -0500 Subject: [PATCH 2/2] Remove trailing whitespace Make the linting tests pass. --- packages/errors/lib/error-handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/errors/lib/error-handler.js b/packages/errors/lib/error-handler.js index 062657c663..9b16fe9923 100644 --- a/packages/errors/lib/error-handler.js +++ b/packages/errors/lib/error-handler.js @@ -25,7 +25,7 @@ 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) { if (error.code >= 500) {