Skip to content

Commit 33fd0e4

Browse files
garrypolleydaffl
authored andcommitted
fix: Do not log as errors below a 500 response (#1256)
1 parent 3f0b1c3 commit 33fd0e4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/errors/lib/error-handler.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ module.exports = function (options = {}) {
2323
}
2424

2525
return function (error, req, res, next) {
26+
// Set the error code for HTTP processing semantics
27+
error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500;
28+
2629
// Log the error if it didn't come from a service method call
2730
if (options.logger && typeof options.logger.error === 'function' && !res.hook) {
28-
options.logger.error(error);
31+
if (error.code >= 500) {
32+
options.logger.error(error);
33+
} else {
34+
options.logger.info(error);
35+
}
2936
}
3037

3138
if (error.type !== 'FeathersError') {
@@ -39,7 +46,6 @@ module.exports = function (options = {}) {
3946
}
4047
}
4148

42-
error.code = !isNaN(parseInt(error.code, 10)) ? parseInt(error.code, 10) : 500;
4349
const formatter = {};
4450

4551
// If the developer passed a custom function for ALL html errors

0 commit comments

Comments
 (0)