Skip to content

Commit 0e7ed77

Browse files
authored
Merge pull request #509 from zhenlineo/4.0-better-connection-error-message
Improving connection error
2 parents 0b8f8b5 + e302d5a commit 0e7ed77

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/internal/node/node-channel.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export default class NodeChannel {
228228
* @param {ChannelConfig} config - configuration for this channel.
229229
*/
230230
constructor (config) {
231-
let self = this
231+
const self = this
232232

233233
this.id = _CONNECTION_IDGEN++
234234
this._pending = []
@@ -257,7 +257,7 @@ export default class NodeChannel {
257257
self._conn.on('end', self._handleConnectionTerminated)
258258

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

272272
_handleConnectionError (err) {
273-
let msg = err.message || 'Failed to connect to server'
273+
let msg =
274+
'Failed to connect to server. ' +
275+
'Please ensure that your database is listening on the correct host and port ' +
276+
'and that you have compatible encryption settings both on Neo4j server and driver. ' +
277+
'Note that the default encryption setting has changed in Neo4j 4.0.'
278+
if (err.message) msg += ' Caused by: ' + err.message
274279
this._error = newError(msg, this._connectionErrorCode)
275280
if (this.onerror) {
276281
this.onerror(this._error)

test/driver.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ describe('#integration driver', () => {
123123
})
124124
.catch(error => {
125125
const doesNotContainAddress = error.message.indexOf(':80') < 0
126+
const doesNotContainBetterErrorMessage =
127+
error.message.indexOf('Failed to connect to server') < 0
126128
if (doesNotContainAddress) {
127129
done.fail(`Expected to contain ':80' but was: ${error.message}`)
130+
} else if (doesNotContainBetterErrorMessage) {
131+
done.fail(
132+
`Expected to contain 'Failed to connect to server' but was: ${error.message}`
133+
)
128134
} else {
129135
expect(error.code).toEqual(neo4j.error.SERVICE_UNAVAILABLE)
130136
done()

0 commit comments

Comments
 (0)