diff --git a/src/server/logging/log_interceptor.js b/src/server/logging/log_interceptor.js index eaddae122aa49..040c0b99442a3 100644 --- a/src/server/logging/log_interceptor.js +++ b/src/server/logging/log_interceptor.js @@ -32,11 +32,13 @@ function doesMessageMatch(errorMessage, match) { if (isRegExp) return match.test(errorMessage); return errorMessage === match; } + // converts the given event into a debug log if it's an error of the given type -function downgradeIfErrorType(errorType, event, field = 'errno') { +function downgradeIfErrorType(errorType, event) { const isClientError = doTagsMatch(event, ['connection', 'client', 'error']); - const matchesErrorType = isClientError && get(event, `error.${field}`) === errorType; + if (!isClientError) return null; + const matchesErrorType = get(event, 'error.code') === errorType || get(event, 'error.errno') === errorType; if (!matchesErrorType) return null; const errorTypeTag = errorType.toLowerCase(); @@ -117,7 +119,7 @@ export class LogInterceptor extends Stream.Transform { } downgradeIfHTTPSWhenHTTP(event) { - return downgradeIfErrorType('HPE_INVALID_METHOD', event, 'code'); + return downgradeIfErrorType('HPE_INVALID_METHOD', event); } downgradeIfHTTPWhenHTTPS(event) { diff --git a/src/server/logging/log_interceptor.test.js b/src/server/logging/log_interceptor.test.js index 43290f9b49737..e56f2f1477eda 100644 --- a/src/server/logging/log_interceptor.test.js +++ b/src/server/logging/log_interceptor.test.js @@ -31,7 +31,7 @@ function stubClientErrorEvent(errorMeta) { }; } -const stubEconnresetEvent = () => stubClientErrorEvent({ errno: 'ECONNRESET' }); +const stubEconnresetEvent = () => stubClientErrorEvent({ code: 'ECONNRESET' }); const stubEpipeEvent = () => stubClientErrorEvent({ errno: 'EPIPE' }); const stubEcanceledEvent = () => stubClientErrorEvent({ errno: 'ECANCELED' });