Skip to content

Merge pull request #197 from eve-bright/fixes-for-bolt-issues #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions app/scripts/services/Bolt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,49 +46,30 @@ angular.module('neo4jApp.services')
driver = bolt.driver("bolt://" + host, bolt.auth.basic(username, password), {encrypted: encrypted})
driver

testQuery = (driver) ->
testConnection = (withoutCredentials = no) ->
q = $q.defer()
driver = getDriverObj withoutCredentials
driver.onError = (e) ->
if e instanceof Event and e.type is 'error'
q.reject getSocketErrorObj()
else if e.code and e.message # until Neo4jError is in drivers public API
q.reject buildErrorObj(e.code, e.message)
session = driver.session()
p = session.run("CALL db.labels")
p.then((r) ->
session.close()
q.resolve r
).catch((e)->
session.close()
q.reject e
)
else if e.fields && e.fields[0]
q.reject e
driver.onCompleted = (m) ->
q.resolve m
driver.session()
q.promise

testConnection = (withoutCredentials = no) ->
connect = (withoutCredentials = no) ->
q = $q.defer()
driver = getDriverObj withoutCredentials
testQuery(driver).then((r) ->
testConnection(withoutCredentials).then((r) ->
_driver = getDriverObj withoutCredentials
q.resolve r
_errorStatus = null
driver.close()
).catch((e) ->
q.reject e
_errorStatus = e
driver.close()
,(e) -> q.reject e
)
q.promise

connect = (withoutCredentials = no) ->
q = $q.defer()
_driver = getDriverObj withoutCredentials
testQuery(_driver)
.then((r) -> q.resolve r)
.catch((e) ->
_driver = null unless e.fields[0].code is 'Neo.ClientError.Security.CredentialsExpired'
q.reject e
)
q.promise

clearConnection = ->
_driver.close() if _driver?
_driver = null
Expand Down Expand Up @@ -130,14 +111,12 @@ angular.module('neo4jApp.services')
session.close()
q.resolve r
).catch((txe) ->
session.close()
q.reject txe
)
else
session.close()
q.resolve r
).catch((e) ->
session.close()
q.reject e
)
else
Expand All @@ -146,7 +125,6 @@ angular.module('neo4jApp.services')
session.close()
q.resolve r
).catch((e) ->
session.close()
q.reject e
)
{tx: tx, promise: q.promise, session: session}
Expand Down
19 changes: 9 additions & 10 deletions app/scripts/services/UtilityBolt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,26 @@ angular.module('neo4jApp.services')
q = $q.defer()
r = Bolt.testConnection withoutCredentials
r.then((r) ->
res = Bolt.constructResult r
Bolt.connect() if retainConnection
if not res.data.errors.length
if (r.credentials_expired)
errObj = {data: {}}
errObj.data.password_change = 'true'
errObj.status = 403
q.reject errObj
else
$rootScope.bolt_connection_failure = no
return q.resolve({})
else
return q.reject({status: 401, data: res})
).catch((err) ->
,(err) ->
errObj = Bolt.constructResult err
if errObj.data.errors[0].code is 'Neo.ClientError.Security.CredentialsExpired'
errObj.data.password_change = 'true'
errObj.status = 403
Bolt.connect() if retainConnection
else if errObj.data.errors[0].code is 'Socket.Error' || errObj.data.errors[0].message.indexOf('WebSocket connection failure') == 0
if errObj.data.errors[0].code is 'Socket.Error' || errObj.data.errors[0].message.indexOf('WebSocket connection failure') == 0
errObj.status = 0
$rootScope.bolt_connection_failure = yes
else
errObj.status = 401
q.reject errObj
)
q.promise

setNewPassword: (username, newPasswd) ->
q = $q.defer()
Bolt.boltTransaction("CALL dbms.changePassword({password})", {password: newPasswd}).promise
Expand Down