Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
http: better client "protocol not supported" error
Browse files Browse the repository at this point in the history
Include the "expected protocol" in the Error message
string, which evaluates to "http:" for the `http`
core module, and "https:" for the `https` module.

Closes #7355.
  • Loading branch information
TooTallNate committed Mar 28, 2014
1 parent 85d595c commit 6d15b16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function ClientRequest(options, cb) {
// an invalid request.
throw new TypeError('Request path contains unescaped characters.');
} else if (protocol !== expectedProtocol) {
throw new Error('Protocol:' + protocol + ' not supported.');
throw new Error('Protocol "' + protocol + '" not supported. ' +
'Expected "' + expectedProtocol + '".');
}

var defaultPort = options.defaultPort || self.agent && self.agent.defaultPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ assert.throws(function() {
http.request(url.parse('file:///whatever'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol:file: not supported.');
assert.strictEqual(err.message, 'Protocol "file:" not supported. Expected "http:".');
return true;
}
});
Expand All @@ -38,7 +38,7 @@ assert.throws(function() {
http.request(url.parse('mailto:asdf@asdf.com'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol:mailto: not supported.');
assert.strictEqual(err.message, 'Protocol "mailto:" not supported. Expected "http:".');
return true;
}
});
Expand All @@ -47,7 +47,7 @@ assert.throws(function() {
http.request(url.parse('ftp://www.example.com'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol:ftp: not supported.');
assert.strictEqual(err.message, 'Protocol "ftp:" not supported. Expected "http:".');
return true;
}
});
Expand All @@ -56,7 +56,7 @@ assert.throws(function() {
http.request(url.parse('javascript:alert(\'hello\');'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol:javascript: not supported.');
assert.strictEqual(err.message, 'Protocol "javascript:" not supported. Expected "http:".');
return true;
}
});
Expand All @@ -65,7 +65,7 @@ assert.throws(function() {
http.request(url.parse('xmpp:isaacschlueter@jabber.org'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol:xmpp: not supported.');
assert.strictEqual(err.message, 'Protocol "xmpp:" not supported. Expected "http:".');
return true;
}
});
Expand All @@ -74,7 +74,7 @@ assert.throws(function() {
http.request(url.parse('f://some.host/path'));
}, function(err) {
if (err instanceof Error) {
assert.strictEqual(err.message, 'Protocol:f: not supported.');
assert.strictEqual(err.message, 'Protocol "f:" not supported. Expected "http:".');
return true;
}
});
Expand Down

0 comments on commit 6d15b16

Please sign in to comment.