Skip to content

Commit afc3930

Browse files
committed
Update exception handling
1 parent 8d61723 commit afc3930

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

lib/connect/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ function connect (brokerUrl, opts) {
5858
opts = opts || {}
5959

6060
if (brokerUrl) {
61+
if (opts.protocol === null) {
62+
throw new Error('Missing protocol')
63+
}
6164
var parsed = new URL(brokerUrl)
6265
// the URL object is a bit special, so copy individual
6366
// items to the opts object
@@ -68,10 +71,6 @@ function connect (brokerUrl, opts) {
6871
opts.username = parsed.username
6972
opts.password = parsed.password
7073
opts.searchParams = parsed.searchParams
71-
72-
if (opts.protocol === null) {
73-
throw new Error('Missing protocol')
74-
}
7574
opts.protocol = opts.protocol.replace(/:$/, '')
7675
}
7776

test/mqtt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('mqtt', function () {
1818
(function () {
1919
var c = mqtt.connect('foo.bar.com')
2020
c.end()
21-
}).should.throw('Missing protocol')
21+
}).should.throw('Invalid URL: foo.bar.com')
2222
})
2323

2424
it('should throw an error when called with no protocol specified - with options', function () {

0 commit comments

Comments
 (0)