Skip to content

Commit 5e99d5a

Browse files
authored
Merge pull request #200 from deploymenttheory/dev
added better error handling to token manager
2 parents 37e74ae + f7d7fd5 commit 5e99d5a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ 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 {
@@ -77,7 +78,12 @@ func (h *AuthTokenHandler) obtainNewToken(apiHandler apihandler.APIHandler, http
7778
backoff *= 2
7879
}
7980

80-
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
8187
}
8288

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

0 commit comments

Comments
 (0)