Skip to content
Prev Previous commit
Next Next commit
errors: update internal/url.js to use internal/errors
  • Loading branch information
jasnell committed Oct 25, 2016
commit 586642520f666cc684e2e59eef0fc6303d6ef8d2
1 change: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ E('INVALID_CALLBACK', 'callback is not a function');
E('INVALID_ENCODING', (encoding) => `Unknown encoding: ${encoding}`);
E('INVALID_FILE_OPEN_FLAG', (flag) => `Unknown file open flag: ${flag}`);
E('INVALID_PORT', 'port must be a number >= 0 and <= 65535');
E('INVALID_URL', 'Invalid URL');
E('NATIVE_MODULE_NOT_FOUND', (module) => `No such native module ${module}`);
E('NO_CRYPTO', 'Node.js is not compiled with openssl crypto support');
E('SOCKET_CLOSED_BEFORE_REPLY', 'Socket closed before reply');
6 changes: 4 additions & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const cannotBeBase = Symbol('cannot-be-base');
const special = Symbol('special');
const searchParams = Symbol('query');
const querystring = require('querystring');
const errors = require('internal/errors');

const kScheme = Symbol('scheme');
const kHost = Symbol('host');
Expand Down Expand Up @@ -81,8 +82,9 @@ class URL {
binding.parse(input.trim(), -1, base_context, undefined,
(flags, protocol, username, password,
host, port, path, query, fragment) => {
if (flags & binding.URL_FLAGS_FAILED)
throw new TypeError('Invalid URL');
if (flags & binding.URL_FLAGS_FAILED) {
throw new errors.TypeError('INVALID_URL');
}
this[context].flags = flags;
this[context].scheme = protocol;
this[context].username = username;
Expand Down