25
25
import org .neo4j .driver .internal .util .Clock ;
26
26
import org .neo4j .driver .internal .util .Consumer ;
27
27
import org .neo4j .driver .v1 .Value ;
28
+ import org .neo4j .driver .v1 .exceptions .ClientException ;
28
29
import org .neo4j .driver .v1 .exceptions .Neo4jException ;
30
+
31
+ import static java .lang .String .format ;
32
+
29
33
/**
30
34
* The state of a pooledConnection from a pool point of view could be one of the following:
31
35
* Created,
@@ -91,7 +95,7 @@ public void run( String statement, Map<String,Value> parameters,
91
95
{
92
96
delegate .run ( statement , parameters , collector );
93
97
}
94
- catch (RuntimeException e )
98
+ catch ( RuntimeException e )
95
99
{
96
100
onDelegateException ( e );
97
101
}
@@ -104,7 +108,7 @@ public void discardAll()
104
108
{
105
109
delegate .discardAll ();
106
110
}
107
- catch (RuntimeException e )
111
+ catch ( RuntimeException e )
108
112
{
109
113
onDelegateException ( e );
110
114
}
@@ -117,7 +121,7 @@ public void pullAll( StreamCollector collector )
117
121
{
118
122
delegate .pullAll ( collector );
119
123
}
120
- catch (RuntimeException e )
124
+ catch ( RuntimeException e )
121
125
{
122
126
onDelegateException ( e );
123
127
}
@@ -224,9 +228,18 @@ public void dispose()
224
228
*/
225
229
private void onDelegateException ( RuntimeException e )
226
230
{
227
- if ( ! isClientOrTransientError ( e ) || isProtocolViolationError ( e ) )
231
+ if ( isUnrecoverableErrorsOccurred ( e ) )
228
232
{
229
233
unrecoverableErrorsOccurred = true ;
234
+ if ( isClusterError ( e ) )
235
+ {
236
+ e = new ClientException ( format (
237
+ "Failed to run a statement on a 3.1+ Neo4j core-edge cluster server. %n" +
238
+ "Please retry the statement if you have defined your own routing strategy to route driver messages to the cluster. " +
239
+ "Note: 1.0 java driver does not support routing statements to a 3.1+ Neo4j core edge cluster. " +
240
+ "Please upgrade to 1.1 driver and use `bolt+routing` scheme to route and run statements " +
241
+ "directly to a 3.1+ core edge cluster." ), e );
242
+ }
230
243
}
231
244
else
232
245
{
@@ -245,18 +258,27 @@ public void onError( Runnable runnable )
245
258
this .onError = runnable ;
246
259
}
247
260
248
- private boolean isProtocolViolationError ( RuntimeException e )
261
+ private boolean isUnrecoverableErrorsOccurred ( RuntimeException e )
249
262
{
250
- return e instanceof Neo4jException
251
- && ((Neo4jException ) e ).neo4jErrorCode ().startsWith ( "Neo.ClientError.Request" );
263
+ return !isClientOrTransientError ( e ) || isProtocolViolationError ( e ) || isClusterError ( e );
264
+ }
265
+
266
+ private boolean isProtocolViolationError ( RuntimeException e )
267
+ {
268
+ return ( e instanceof Neo4jException ) &&
269
+ ( ( Neo4jException ) e ).neo4jErrorCode ().startsWith ( "Neo.ClientError.Request" );
252
270
}
253
271
254
272
private boolean isClientOrTransientError ( RuntimeException e )
255
273
{
256
274
// Eg: DatabaseErrors and unknown (no status code or not neo4j exception) cause session to be discarded
257
- return e instanceof Neo4jException
258
- && (((Neo4jException ) e ).neo4jErrorCode ().contains ( "ClientError" )
259
- || ((Neo4jException ) e ).neo4jErrorCode ().contains ( "TransientError" ));
275
+ return ( e instanceof Neo4jException ) && ( ( Neo4jException ) e ).neo4jErrorCode ().contains ( "ClientError" )
276
+ || ( e instanceof Neo4jException ) && ( ( Neo4jException ) e ).neo4jErrorCode ().contains ( "TransientError" );
277
+ }
278
+
279
+ private boolean isClusterError ( RuntimeException e )
280
+ {
281
+ return ( e instanceof Neo4jException ) && ( ( Neo4jException ) e ).neo4jErrorCode ().contains ( "Cluster" );
260
282
}
261
283
262
284
public long idleTime ()
0 commit comments