@@ -697,20 +697,30 @@ class Account {
697697 accountData . _app = app ;
698698 }
699699 } else if ( accountData . oauth2 && accountData . oauth2 . auth && accountData . oauth2 . auth . delegatedAccount ) {
700- let delegatedAccount = await resolveDelegatedAccount ( this . redis , accountData . account ) ;
701- if ( delegatedAccount ) {
702- accountData . delegatedAccount = delegatedAccount ;
703- let delegatedAccountRow = await this . redis . hgetall ( `${ REDIS_PREFIX } iad:${ delegatedAccount } ` ) ;
704- let delegatedAccountData = this . unserializeAccountData ( delegatedAccountRow ) ;
705- if ( delegatedAccountData . oauth2 && delegatedAccountData . oauth2 . provider ) {
706- let app = await oauth2Apps . get ( delegatedAccountData . oauth2 . provider ) ;
707- if ( app ) {
708- accountData . _app = app ;
709- if ( app . baseScopes === 'api' ) {
710- accountData . isApi = true ;
700+ try {
701+ let delegatedAccount = await resolveDelegatedAccount ( this . redis , accountData . account ) ;
702+ if ( delegatedAccount ) {
703+ accountData . delegatedAccount = delegatedAccount ;
704+ let delegatedAccountRow = await this . redis . hgetall ( `${ REDIS_PREFIX } iad:${ delegatedAccount } ` ) ;
705+ let delegatedAccountData = this . unserializeAccountData ( delegatedAccountRow ) ;
706+ if ( delegatedAccountData . oauth2 && delegatedAccountData . oauth2 . provider ) {
707+ let app = await oauth2Apps . get ( delegatedAccountData . oauth2 . provider ) ;
708+ if ( app ) {
709+ accountData . _app = app ;
710+ if ( app . baseScopes === 'api' ) {
711+ accountData . isApi = true ;
712+ }
711713 }
712714 }
713715 }
716+ } catch ( err ) {
717+ this . logger . warn ( {
718+ msg : 'Failed to resolve delegated account' ,
719+ account : accountData . account ,
720+ delegatedAccount : accountData . oauth2 . auth . delegatedAccount ,
721+ err
722+ } ) ;
723+ accountData . delegationError = err . message ;
714724 }
715725 }
716726
@@ -2545,17 +2555,22 @@ class Account {
25452555
25462556 async isApiClient ( accountData ) {
25472557 if ( accountData . oauth2 ?. auth ?. delegatedAccount ) {
2548- let delegatedAccount = await resolveDelegatedAccount ( this . redis , accountData . account ) ;
2549- if ( delegatedAccount ) {
2550- accountData . delegatedAccount = delegatedAccount ;
2551- let delegatedAccountRow = await this . redis . hgetall ( `${ REDIS_PREFIX } iad:${ delegatedAccount } ` ) ;
2552- let delegatedAccountData = this . unserializeAccountData ( delegatedAccountRow ) ;
2553- if ( delegatedAccountData ?. oauth2 ?. provider ) {
2554- let app = await oauth2Apps . get ( delegatedAccountData . oauth2 . provider ) ;
2555- return app ?. baseScopes === 'api' ;
2556- } else {
2557- return false ;
2558+ try {
2559+ let delegatedAccount = await resolveDelegatedAccount ( this . redis , accountData . account ) ;
2560+ if ( delegatedAccount ) {
2561+ accountData . delegatedAccount = delegatedAccount ;
2562+ let delegatedAccountRow = await this . redis . hgetall ( `${ REDIS_PREFIX } iad:${ delegatedAccount } ` ) ;
2563+ let delegatedAccountData = this . unserializeAccountData ( delegatedAccountRow ) ;
2564+ if ( delegatedAccountData ?. oauth2 ?. provider ) {
2565+ let app = await oauth2Apps . get ( delegatedAccountData . oauth2 . provider ) ;
2566+ return app ?. baseScopes === 'api' ;
2567+ } else {
2568+ return false ;
2569+ }
25582570 }
2571+ } catch ( err ) {
2572+ // Invalid delegation config - treat as non-API client
2573+ return false ;
25592574 }
25602575 }
25612576
0 commit comments