Skip to content

Improving connection error #509

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
Dec 4, 2019
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
11 changes: 8 additions & 3 deletions src/internal/node/node-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default class NodeChannel {
* @param {ChannelConfig} config - configuration for this channel.
*/
constructor (config) {
let self = this
const self = this

this.id = _CONNECTION_IDGEN++
this._pending = []
Expand Down Expand Up @@ -257,7 +257,7 @@ export default class NodeChannel {
self._conn.on('end', self._handleConnectionTerminated)

// Drain all pending messages
let pending = self._pending
const pending = self._pending
self._pending = null
for (let i = 0; i < pending.length; i++) {
self.write(pending[i])
Expand All @@ -270,7 +270,12 @@ export default class NodeChannel {
}

_handleConnectionError (err) {
let msg = err.message || 'Failed to connect to server'
let msg =
'Failed to connect to server. ' +
'Please ensure that your database is listening on the correct host and port ' +
'and that you have compatible encryption settings both on Neo4j server and driver. ' +
'Note that the default encryption setting has changed in Neo4j 4.0.'
if (err.message) msg += ' Caused by: ' + err.message
this._error = newError(msg, this._connectionErrorCode)
if (this.onerror) {
this.onerror(this._error)
Expand Down
6 changes: 6 additions & 0 deletions test/driver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ describe('#integration driver', () => {
})
.catch(error => {
const doesNotContainAddress = error.message.indexOf(':80') < 0
const doesNotContainBetterErrorMessage =
error.message.indexOf('Failed to connect to server') < 0
if (doesNotContainAddress) {
done.fail(`Expected to contain ':80' but was: ${error.message}`)
} else if (doesNotContainBetterErrorMessage) {
done.fail(
`Expected to contain 'Failed to connect to server' but was: ${error.message}`
)
} else {
expect(error.code).toEqual(neo4j.error.SERVICE_UNAVAILABLE)
done()
Expand Down