Skip to content

Commit f7d7fd5

Browse files
committed
Refactor error handling in OAuth2TokenAcquisition function
1 parent a846913 commit f7d7fd5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

authenticationhandler/oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (h *AuthTokenHandler) OAuth2TokenAcquisition(apiHandler apihandler.APIHandl
7676
err = json.Unmarshal(bodyBytes, oauthResp)
7777
if err != nil {
7878
h.Logger.Error("Failed to decode OAuth response", zap.Error(err))
79-
return err
79+
return fmt.Errorf("failed to decode OAuth response: %w", err)
8080
}
8181

8282
if oauthResp.Error != "" {

authenticationhandler/tokenmanager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ func (h *AuthTokenHandler) obtainNewToken(apiHandler apihandler.APIHandler, http
6666
} else {
6767
err = fmt.Errorf("no valid credentials provided. Unable to obtain a token")
6868
h.Logger.Error("Authentication method not supported", zap.String("AuthMethod", h.AuthMethod))
69+
return err // Return the error immediately
6970
}
7071

7172
if err == nil {
72-
h.Logger.Info("Successfully obtained new token", zap.String("AuthMethod", h.AuthMethod))
7373
break
7474
}
7575

@@ -78,7 +78,12 @@ func (h *AuthTokenHandler) obtainNewToken(apiHandler apihandler.APIHandler, http
7878
backoff *= 2
7979
}
8080

81-
return err
81+
if err != nil {
82+
h.Logger.Error("Failed to obtain new token after all attempts", zap.Error(err))
83+
return err
84+
}
85+
86+
return nil
8287
}
8388

8489
// refreshTokenIfNeeded refreshes the token if it's close to expiration.

0 commit comments

Comments
 (0)