Skip to content

Commit 239c958

Browse files
author
Daniel Mewes
committed
Fix for JavaScript driver auth error handling.
OTS reviewed by @nighelles
1 parent db5de6c commit 239c958

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

net.coffee

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,9 @@ class TcpConnection extends Connection
10821082

10831083
handshake_error = (code, message) =>
10841084
if 10 <= code <= 20
1085-
throw new err.ReqlAuthError(message)
1085+
@emit 'error', new err.ReqlAuthError(message)
10861086
else
1087-
throw new err.ReqlDriverError(message)
1087+
@emit 'error', new err.ReqlDriverError(message)
10881088

10891089
handshake_callback = (buf) =>
10901090
# Once we receive a response, extend the current
@@ -1114,6 +1114,7 @@ class TcpConnection extends Connection
11141114
if state is 1
11151115
if not server_reply.success
11161116
handshake_error(server_reply.error_code, server_reply.error)
1117+
return
11171118
min = server_reply.min_protocol_version
11181119
max = server_reply.max_protocol_version
11191120

@@ -1126,6 +1127,7 @@ class TcpConnection extends Connection
11261127
else if state is 2
11271128
if not server_reply.success
11281129
handshake_error(server_reply.error_code, server_reply.error)
1130+
return
11291131

11301132
authentication = {}
11311133
server_first_message = server_reply.authentication
@@ -1167,6 +1169,7 @@ class TcpConnection extends Connection
11671169
else if state is 3
11681170
if not server_reply.success
11691171
handshake_error(server_reply.error_code, server_reply.error)
1172+
return
11701173

11711174
first_equals = server_reply.authentication.indexOf('=')
11721175
v = server_reply.authentication.slice(first_equals+1)
@@ -1632,13 +1635,12 @@ module.exports.connect = varar 0, 2, (hostOrCallback, callback) ->
16321635
# or in the browser.
16331636
# 2. Initializes the connection, and when it's complete invokes
16341637
# the user's callback
1635-
if host.authKey? && (host.password? || host.user?)
1636-
throw new err.ReqlDriverError "Cannot use both authKey and password"
1637-
else if host.authKey
1638-
host.user = "admin"
1639-
host.password = host.authKey
1640-
16411638
new Promise( (resolve, reject) ->
1639+
if host.authKey? && (host.password? || host.user?)
1640+
throw new err.ReqlDriverError "Cannot use both authKey and password"
1641+
else if host.authKey
1642+
host.user = "admin"
1643+
host.password = host.authKey
16421644
create_connection = (host, callback) =>
16431645
if TcpConnection.isAvailable()
16441646
new TcpConnection host, callback

0 commit comments

Comments
 (0)