@@ -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 )
@@ -453,14 +459,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
453
459
impersonatedUser
454
460
)
455
461
} catch ( error ) {
456
- if ( error && error . code === DATABASE_NOT_FOUND_ERROR_CODE ) {
457
- // not finding the target database is a sign of a configuration issue
458
- throw error
459
- }
460
- this . _log . warn (
461
- `unable to fetch routing table because of an error ${ error } `
462
- )
463
- return null
462
+ return this . _handleRediscoveryError ( error )
464
463
} finally {
465
464
session . close ( )
466
465
}
@@ -503,16 +502,26 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
503
502
impersonatedUser
504
503
} )
505
504
} catch ( error ) {
506
- // unable to acquire connection towards the given router
507
- if ( error && error . code === UNAUTHORIZED_ERROR_CODE ) {
508
- // auth error and not finding system database is a sign of a configuration issue
509
- // discovery should not proceed
510
- throw error
511
- }
512
- return null
505
+ return this . _handleRediscoveryError ( error )
513
506
}
514
507
}
515
508
509
+ _handleRediscoveryError ( error ) {
510
+ if ( _isFailFastError ( error ) || _isFailFastSecurityError ( error ) ) {
511
+ throw error
512
+ } else if ( error . code === PROCEDURE_NOT_FOUND_CODE ) {
513
+ // throw when getServers procedure not found because this is clearly a configuration issue
514
+ throw newError (
515
+ `Server at ${ routerAddress . asHostPort ( ) } can't perform routing. Make sure you are connecting to a causal cluster` ,
516
+ SERVICE_UNAVAILABLE
517
+ )
518
+ }
519
+ this . _log . warn (
520
+ `unable to fetch routing table because of an error ${ error } `
521
+ )
522
+ return null
523
+ }
524
+
516
525
async _applyRoutingTableIfPossible ( currentRoutingTable , newRoutingTable , onDatabaseNameResolved ) {
517
526
if ( ! newRoutingTable ) {
518
527
// none of routing servers returned valid routing table, throw exception
@@ -647,3 +656,20 @@ class RoutingTableRegistry {
647
656
return this
648
657
}
649
658
}
659
+
660
+ function _isFailFastError ( error ) {
661
+ return [
662
+ DATABASE_NOT_FOUND_CODE ,
663
+ FORBIDEN_CODE ,
664
+ INVALID_BOOKMARK_CODE ,
665
+ INVALID_BOOKMARK_MIXTURE_CODE ,
666
+ ] . includes ( error . code )
667
+ }
668
+
669
+ function _isFailFastSecurityError ( error ) {
670
+ return error . code . startsWith ( 'Neo.ClientError.Security.' ) &&
671
+ ! [
672
+
673
+ ] . includes ( error . code )
674
+ }
675
+
0 commit comments