@@ -118,25 +118,26 @@ class AuthHandler {
118118 if ( result . user ) {
119119 log . debug ( 'Login successful, user found' , { module : 'auth-handler' , userEmail : result . user . email } ) ;
120120 resolve ( result . user as User ) ;
121- } else if ( result . error_code === 294 ) {
122- const tfToken = await this . handleOTPFlow ( tfaToken , loginPayload ) ;
123-
121+ } else {
122+ log . debug ( 'Login failed: no user found.' , { module : 'auth-handler' , result } ) ;
123+ reject ( new Error ( messageHandler . parse ( 'CLI_AUTH_LOGIN_NO_USER' ) ) ) ;
124+ }
125+ } )
126+ . catch ( async ( error : any ) => {
127+ if ( error . errorCode === 294 ) {
124128 try {
129+ const tfToken = await this . handleOTPFlow ( tfaToken , loginPayload ) ;
125130 resolve ( await this . login ( email , password , tfToken ) ) ;
126131 } catch ( error ) {
127132 log . debug ( 'Login with TFA token failed.' , { module : 'auth-handler' , error } ) ;
128133 cliux . print ( 'CLI_AUTH_2FA_FAILED' , { color : 'red' } ) ;
129134 reject ( error ) ;
130135 }
131136 } else {
132- log . debug ( 'Login failed: no user found.' , { module : 'auth-handler' , result } ) ;
133- reject ( new Error ( messageHandler . parse ( 'CLI_AUTH_LOGIN_NO_USER' ) ) ) ;
137+ log . debug ( 'Login API call failed.' , { module : 'auth-handler' , error : error ?. errorMessage || error } ) ;
138+ cliux . print ( 'CLI_AUTH_LOGIN_FAILED' , { color : 'yellow' } ) ;
139+ reject ( error ) ;
134140 }
135- } )
136- . catch ( ( error : any ) => {
137- log . debug ( 'Login API call failed.' , { module : 'auth-handler' , error : error ?. errorMessage || error } ) ;
138- cliux . print ( 'CLI_AUTH_LOGIN_FAILED' , { color : 'yellow' } ) ;
139- handleAndLogError ( error , { module : 'auth-handler' } ) ;
140141 } ) ;
141142 } else {
142143 const hasEmail = ! ! email ;
@@ -203,7 +204,7 @@ class AuthHandler {
203204 . catch ( ( error : Error ) => {
204205 log . debug ( 'Token validation failed.' , { module : 'auth-handler' , error : error . message } ) ;
205206 cliux . print ( 'CLI_AUTH_TOKEN_VALIDATION_FAILED' , { color : 'yellow' } ) ;
206- handleAndLogError ( error , { module : 'auth-handler' } ) ;
207+ reject ( error ) ;
207208 } ) ;
208209 } else {
209210 log . debug ( 'Token validation failed: no auth token provided.' , { module : 'auth-handler' } ) ;
0 commit comments