@@ -41,9 +41,15 @@ const {
41
41
}
42
42
} = internal
43
43
44
+
45
+ const PROCEDURE_NOT_FOUND_CODE = 'Neo.ClientError.Procedure.ProcedureNotFound'
46
+ const DATABASE_NOT_FOUND_CODE = 'Neo.ClientError.Database.DatabaseNotFound'
47
+ const INVALID_BOOKMARK_CODE = 'Neo.ClientError.Transaction.InvalidBookmark'
48
+ const INVALID_BOOKMARK_MIXTURE_CODE =
49
+ 'Neo.ClientError.Transaction.InvalidBookmarkMixture'
50
+ const FORBIDEN_CODE = 'Neo.ClientError.Security.Forbidden'
44
51
const UNAUTHORIZED_ERROR_CODE = 'Neo.ClientError.Security.Unauthorized'
45
- const DATABASE_NOT_FOUND_ERROR_CODE =
46
- 'Neo.ClientError.Database.DatabaseNotFound'
52
+
47
53
const SYSTEM_DB_NAME = 'system'
48
54
const DEFAULT_DB_NAME = null
49
55
const DEFAULT_ROUTING_TABLE_PURGE_DELAY = int ( 30000 )
@@ -482,14 +488,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
482
488
impersonatedUser
483
489
)
484
490
} catch ( error ) {
485
- if ( error && error . code === DATABASE_NOT_FOUND_ERROR_CODE ) {
486
- // not finding the target database is a sign of a configuration issue
487
- throw error
488
- }
489
- this . _log . warn (
490
- `unable to fetch routing table because of an error ${ error } `
491
- )
492
- return null
491
+ return this . _handleRediscoveryError ( error )
493
492
} finally {
494
493
session . close ( )
495
494
}
@@ -532,16 +531,26 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
532
531
impersonatedUser
533
532
} )
534
533
} catch ( error ) {
535
- // unable to acquire connection towards the given router
536
- if ( error && error . code === UNAUTHORIZED_ERROR_CODE ) {
537
- // auth error and not finding system database is a sign of a configuration issue
538
- // discovery should not proceed
539
- throw error
540
- }
541
- return null
534
+ return this . _handleRediscoveryError ( error )
542
535
}
543
536
}
544
537
538
+ _handleRediscoveryError ( error ) {
539
+ if ( _isFailFastError ( error ) || _isFailFastSecurityError ( error ) ) {
540
+ throw error
541
+ } else if ( error . code === PROCEDURE_NOT_FOUND_CODE ) {
542
+ // throw when getServers procedure not found because this is clearly a configuration issue
543
+ throw newError (
544
+ `Server at ${ routerAddress . asHostPort ( ) } can't perform routing. Make sure you are connecting to a causal cluster` ,
545
+ SERVICE_UNAVAILABLE
546
+ )
547
+ }
548
+ this . _log . warn (
549
+ `unable to fetch routing table because of an error ${ error } `
550
+ )
551
+ return null
552
+ }
553
+
545
554
async _applyRoutingTableIfPossible ( currentRoutingTable , newRoutingTable , onDatabaseNameResolved ) {
546
555
if ( ! newRoutingTable ) {
547
556
// none of routing servers returned valid routing table, throw exception
@@ -676,3 +685,20 @@ class RoutingTableRegistry {
676
685
return this
677
686
}
678
687
}
688
+
689
+ function _isFailFastError ( error ) {
690
+ return [
691
+ DATABASE_NOT_FOUND_CODE ,
692
+ FORBIDEN_CODE ,
693
+ INVALID_BOOKMARK_CODE ,
694
+ INVALID_BOOKMARK_MIXTURE_CODE ,
695
+ ] . includes ( error . code )
696
+ }
697
+
698
+ function _isFailFastSecurityError ( error ) {
699
+ return error . code . startsWith ( 'Neo.ClientError.Security.' ) &&
700
+ ! [
701
+
702
+ ] . includes ( error . code )
703
+ }
704
+
0 commit comments