diff options
author | Weijia Wang <381152119@qq.com> | 2017-07-22 19:23:04 +0800 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2017-08-01 14:08:12 +0200 |
commit | bdfbce924159ece4b32ee7f774a263987e719972 (patch) | |
tree | 2134a4937c1d751de771abe92d00c8cf47fc2307 /lib/_http_client.js | |
parent | 8db39971b768118ce2c0c34d88788daea14f52c9 (diff) | |
download | android-node-v8-bdfbce924159ece4b32ee7f774a263987e719972.tar.gz android-node-v8-bdfbce924159ece4b32ee7f774a263987e719972.tar.bz2 android-node-v8-bdfbce924159ece4b32ee7f774a263987e719972.zip |
http_client, errors: migrate to internal/errors
PR-URL: https://github.com/nodejs/node/pull/14423
Refs: https://github.com/nodejs/node/issues/11273
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'lib/_http_client.js')
-rw-r--r-- | lib/_http_client.js | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/_http_client.js b/lib/_http_client.js index 29ea688ecb..f141fd785c 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -37,6 +37,7 @@ const Buffer = require('buffer').Buffer; const { urlToOptions, searchParamsSymbol } = require('internal/url'); const outHeadersKey = require('internal/http').outHeadersKey; const nextTick = require('internal/process/next_tick').nextTick; +const errors = require('internal/errors'); // The actual list of disallowed characters in regexp form is more like: // /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/ @@ -68,8 +69,8 @@ function isInvalidPath(s) { function validateHost(host, name) { if (host != null && typeof host !== 'string') { - throw new TypeError( - `"options.${name}" must either be a string, undefined or null`); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', `options.${name}`, + ['string', 'undefined', 'null'], host); } return host; } @@ -80,7 +81,7 @@ function ClientRequest(options, cb) { if (typeof options === 'string') { options = url.parse(options); if (!options.hostname) { - throw new Error('Unable to determine the domain name'); + throw new errors.Error('ERR_INVALID_DOMAIN_NAME'); } } else if (options && options[searchParamsSymbol] && options[searchParamsSymbol][searchParamsSymbol]) { @@ -101,9 +102,8 @@ function ClientRequest(options, cb) { // Explicitly pass through this statement as agent will not be used // when createConnection is provided. } else if (typeof agent.addRequest !== 'function') { - throw new TypeError( - 'Agent option must be an Agent-like object, undefined, or false.' - ); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'Agent option', + ['Agent-like object', 'undefined', 'false']); } this.agent = agent; @@ -122,12 +122,11 @@ function ClientRequest(options, cb) { invalidPath = /[\u0000-\u0020]/.test(path); } if (invalidPath) - throw new TypeError('Request path contains unescaped characters'); + throw new errors.TypeError('ERR_UNESCAPED_CHARACTERS', 'Request path'); } if (protocol !== expectedProtocol) { - throw new Error('Protocol "' + protocol + '" not supported. ' + - 'Expected "' + expectedProtocol + '"'); + throw new errors.Error('ERR_INVALID_PROTOCOL', protocol, expectedProtocol); } var defaultPort = options.defaultPort || @@ -145,12 +144,13 @@ function ClientRequest(options, cb) { var method = options.method; var methodIsString = (typeof method === 'string'); if (method != null && !methodIsString) { - throw new TypeError('Method must be a string'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'method', + 'string', method); } if (methodIsString && method) { if (!common._checkIsHttpToken(method)) { - throw new TypeError('Method must be a valid HTTP token'); + throw new errors.TypeError('ERR_INVALID_HTTP_TOKEN', 'Method'); } method = this.method = method.toUpperCase(); } else { @@ -211,8 +211,7 @@ function ClientRequest(options, cb) { options.headers); } else if (this.getHeader('expect')) { if (this._header) { - throw new Error('Can\'t render headers after they are sent to the ' + - 'client'); + throw new errors.Error('ERR_HTTP_HEADERS_SENT'); } this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', @@ -303,7 +302,7 @@ ClientRequest.prototype._finish = function _finish() { ClientRequest.prototype._implicitHeader = function _implicitHeader() { if (this._header) { - throw new Error('Can\'t render headers after they are sent to the client'); + throw new errors.Error('ERR_HTTP_HEADERS_SENT'); } this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', this[outHeadersKey]); |