From 161509341ed77ee7e77c321a65c8bf628d7e0e9d Mon Sep 17 00:00:00 2001 From: Sebastian Van Sande Date: Fri, 10 Feb 2017 17:45:15 +0100 Subject: [PATCH] https: use internal/errors.js --- doc/api/errors.md | 8 +++++++- lib/https.js | 3 ++- lib/internal/errors.js | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index ebafd5a05fba54..8e1fc4fe432bcf 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -558,7 +558,7 @@ found [here][online]. the connected party did not properly respond after a period of time. Usually encountered by [`http`][] or [`net`][] -- often a sign that a `socket.end()` was not properly called. - + ## Node.js Error Codes @@ -703,6 +703,12 @@ in some cases may accept `func(undefined)` but not `func()`). In most native Node.js APIs, `func(undefined)` and `func()` are treated identically, and the [`ERR_INVALID_ARG_TYPE`][] error code may be used instead. + +### ERR_HTTP_NO_DOMAIN + +An error using the `'ERR_HTTP_NO_DOMAIN'` code is thrown specifically when an attempt +is made to parse an URL without a valid domain name. + ### ERR_STDERR_CLOSE diff --git a/lib/https.js b/lib/https.js index f0ecbd90a6700f..1da6a229f59a2f 100644 --- a/lib/https.js +++ b/lib/https.js @@ -30,6 +30,7 @@ const util = require('util'); const inherits = util.inherits; const debug = util.debuglog('https'); const { urlToOptions, searchParamsSymbol } = require('internal/url'); +const errors = require('internal/errors'); function Server(opts, requestListener) { if (!(this instanceof Server)) return new Server(opts, requestListener); @@ -219,7 +220,7 @@ exports.request = function request(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_HTTP_NO_DOMAIN'); } } else if (options && options[searchParamsSymbol] && options[searchParamsSymbol][searchParamsSymbol]) { diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 50d2c20325f0d6..1ce676d783a186 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -136,6 +136,7 @@ E('ERR_IPC_DISCONNECTED', 'IPC channel is already disconnected'); E('ERR_IPC_ONE_PIPE', 'Child process can have only one IPC pipe'); E('ERR_IPC_SYNC_FORK', 'IPC cannot be used with synchronous forks'); E('ERR_MISSING_ARGS', missingArgs); +E('ERR_HTTP_NO_DOMAIN', 'Unable to determine the domain name'); E('ERR_STDERR_CLOSE', 'process.stderr cannot be closed'); E('ERR_STDOUT_CLOSE', 'process.stdout cannot be closed'); E('ERR_UNKNOWN_BUILTIN_MODULE', (id) => `No such built-in module: ${id}`);