File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ const TrustStrategy = {
91
91
onSuccess ( ) ;
92
92
}
93
93
} ) ;
94
+ socket . on ( 'error' , onFailure ) ;
94
95
return socket ;
95
96
} ,
96
97
TRUST_ON_FIRST_USE : function ( opts , onSuccess , onFailure ) {
@@ -139,13 +140,16 @@ const TrustStrategy = {
139
140
}
140
141
} ) ;
141
142
} ) ;
143
+ socket . on ( 'error' , onFailure ) ;
142
144
return socket ;
143
145
}
144
146
} ;
145
147
146
148
function connect ( opts , onSuccess , onFailure = ( ( ) => null ) ) {
147
149
if ( opts . encrypted === false ) {
148
- return net . connect ( opts . port , opts . host , onSuccess ) ;
150
+ var conn = net . connect ( opts . port , opts . host , onSuccess ) ;
151
+ conn . on ( 'error' , onFailure ) ;
152
+ return conn ;
149
153
} else if ( TrustStrategy [ opts . trust ] ) {
150
154
return TrustStrategy [ opts . trust ] ( opts , onSuccess , onFailure ) ;
151
155
} else {
Original file line number Diff line number Diff line change @@ -57,6 +57,13 @@ class WebSocketChannel {
57
57
this . _ws . binaryType = "arraybuffer" ;
58
58
59
59
let self = this ;
60
+ //All connection errors are not sent to the error handler
61
+ //we must also check for dirty close calls
62
+ this . _ws . onclose = function ( e ) {
63
+ if ( ! e . wasClean ) {
64
+ self . _handleConnectionError ( ) ;
65
+ }
66
+ } ;
60
67
this . _ws . onopen = function ( ) {
61
68
// Drain all pending messages
62
69
let pending = self . _pending ;
Original file line number Diff line number Diff line change @@ -32,4 +32,19 @@ describe('driver', function() {
32
32
expect ( session ) . not . toBeNull ( ) ;
33
33
driver . close ( ) ;
34
34
} ) ;
35
+
36
+ it ( 'should handle connection errors' , function ( done ) {
37
+ // Given
38
+ var driver = neo4j . driver ( "bolt://localhoste" , neo4j . auth . basic ( "neo4j" , "neo4j" ) ) ;
39
+
40
+ // Expect
41
+ driver . onError = function ( err ) {
42
+ //the error message is different whether in browser or node
43
+ expect ( err . message ) . not . toBeNull ( ) ;
44
+ done ( ) ;
45
+ } ;
46
+
47
+ // When
48
+ driver . session ( ) ;
49
+ } ) ;
35
50
} ) ;
You can’t perform that action at this time.
0 commit comments