summaryrefslogtreecommitdiff
path: root/lib/_http_client.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-05-29 08:03:21 -0700
committerRich Trott <rtrott@gmail.com>2019-05-31 21:21:19 +0200
commitaa8b820aaa4d36085baaf8beb1187b2b9955fffb (patch)
treed8fdda3d23a03fe4161916bc5b75a1d71366311f /lib/_http_client.js
parentd05668d6884992765e94cec2ba755feb946071c1 (diff)
downloadnode-new-aa8b820aaa4d36085baaf8beb1187b2b9955fffb.tar.gz
errors: create internal connResetException
Replace various instances of errors that use code ECONNRESET with a single centralized factory function to create the errors. (While making changes to _tls_wrap.js, this also takes the opportunity to make trailing commas consistent on multi-line arrays. One had a trailing comma and one didn't. This adds a traiiling comma to the one that didn't.) PR-URL: https://github.com/nodejs/node/pull/27953 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib/_http_client.js')
-rw-r--r--lib/_http_client.js16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js
index bc2c2af8ac..bc2716b254 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -40,13 +40,14 @@ const { Buffer } = require('buffer');
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
const { URL, urlToOptions, searchParamsSymbol } = require('internal/url');
const { outHeadersKey, ondrain } = require('internal/http');
+const { connResetException, codes } = require('internal/errors');
const {
ERR_HTTP_HEADERS_SENT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_HTTP_TOKEN,
ERR_INVALID_PROTOCOL,
ERR_UNESCAPED_CHARACTERS
-} = require('internal/errors').codes;
+} = codes;
const { getTimerDuration } = require('internal/timers');
const {
DTRACE_HTTP_CLIENT_REQUEST,
@@ -337,15 +338,6 @@ function emitAbortNT() {
this.emit('abort');
}
-
-function createHangUpError() {
- // eslint-disable-next-line no-restricted-syntax
- const error = new Error('socket hang up');
- error.code = 'ECONNRESET';
- return error;
-}
-
-
function socketCloseListener() {
const socket = this;
const req = socket._httpMessage;
@@ -381,7 +373,7 @@ function socketCloseListener() {
// receive a response. The error needs to
// fire on the request.
req.socket._hadError = true;
- req.emit('error', createHangUpError());
+ req.emit('error', connResetException('socket hang up'));
}
req.emit('close');
}
@@ -441,7 +433,7 @@ function socketOnEnd() {
// If we don't have a response then we know that the socket
// ended prematurely and we need to emit an error on the request.
req.socket._hadError = true;
- req.emit('error', createHangUpError());
+ req.emit('error', connResetException('socket hang up'));
}
if (parser) {
parser.finish();