2525import org .neo4j .driver .internal .util .Clock ;
2626import org .neo4j .driver .internal .util .Consumer ;
2727import org .neo4j .driver .v1 .Value ;
28+ import org .neo4j .driver .v1 .exceptions .ClientException ;
2829import org .neo4j .driver .v1 .exceptions .Neo4jException ;
30+
31+ import static java .lang .String .format ;
32+
2933/**
3034 * The state of a pooledConnection from a pool point of view could be one of the following:
3135 * Created,
@@ -91,7 +95,7 @@ public void run( String statement, Map<String,Value> parameters,
9195 {
9296 delegate .run ( statement , parameters , collector );
9397 }
94- catch (RuntimeException e )
98+ catch ( RuntimeException e )
9599 {
96100 onDelegateException ( e );
97101 }
@@ -104,7 +108,7 @@ public void discardAll()
104108 {
105109 delegate .discardAll ();
106110 }
107- catch (RuntimeException e )
111+ catch ( RuntimeException e )
108112 {
109113 onDelegateException ( e );
110114 }
@@ -117,7 +121,7 @@ public void pullAll( StreamCollector collector )
117121 {
118122 delegate .pullAll ( collector );
119123 }
120- catch (RuntimeException e )
124+ catch ( RuntimeException e )
121125 {
122126 onDelegateException ( e );
123127 }
@@ -224,9 +228,18 @@ public void dispose()
224228 */
225229 private void onDelegateException ( RuntimeException e )
226230 {
227- if ( ! isClientOrTransientError ( e ) || isProtocolViolationError ( e ) )
231+ if ( isUnrecoverableErrorsOccurred ( e ) )
228232 {
229233 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+ }
230243 }
231244 else
232245 {
@@ -245,18 +258,27 @@ public void onError( Runnable runnable )
245258 this .onError = runnable ;
246259 }
247260
248- private boolean isProtocolViolationError ( RuntimeException e )
261+ private boolean isUnrecoverableErrorsOccurred ( RuntimeException e )
249262 {
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" );
252270 }
253271
254272 private boolean isClientOrTransientError ( RuntimeException e )
255273 {
256274 // 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" );
260282 }
261283
262284 public long idleTime ()
0 commit comments