From a846913e52d8d5f7a64756d93da154a45ae853d9 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Sat, 25 May 2024 18:30:49 +0100 Subject: [PATCH 1/2] chore: Update token acquisition logging in TokenManager --- authenticationhandler/tokenmanager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/authenticationhandler/tokenmanager.go b/authenticationhandler/tokenmanager.go index 4944d10..e3f7753 100644 --- a/authenticationhandler/tokenmanager.go +++ b/authenticationhandler/tokenmanager.go @@ -69,6 +69,7 @@ func (h *AuthTokenHandler) obtainNewToken(apiHandler apihandler.APIHandler, http } if err == nil { + h.Logger.Info("Successfully obtained new token", zap.String("AuthMethod", h.AuthMethod)) break } From f7d7fd5bfcf8dcbf559f2f42d846ea7e9ae38bf1 Mon Sep 17 00:00:00 2001 From: ShocOne <62835948+ShocOne@users.noreply.github.com> Date: Sun, 26 May 2024 19:40:12 +0100 Subject: [PATCH 2/2] Refactor error handling in OAuth2TokenAcquisition function --- authenticationhandler/oauth2.go | 2 +- authenticationhandler/tokenmanager.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/authenticationhandler/oauth2.go b/authenticationhandler/oauth2.go index 8f2a100..9cc16a2 100644 --- a/authenticationhandler/oauth2.go +++ b/authenticationhandler/oauth2.go @@ -76,7 +76,7 @@ func (h *AuthTokenHandler) OAuth2TokenAcquisition(apiHandler apihandler.APIHandl err = json.Unmarshal(bodyBytes, oauthResp) if err != nil { h.Logger.Error("Failed to decode OAuth response", zap.Error(err)) - return err + return fmt.Errorf("failed to decode OAuth response: %w", err) } if oauthResp.Error != "" { diff --git a/authenticationhandler/tokenmanager.go b/authenticationhandler/tokenmanager.go index e3f7753..04bb859 100644 --- a/authenticationhandler/tokenmanager.go +++ b/authenticationhandler/tokenmanager.go @@ -66,10 +66,10 @@ func (h *AuthTokenHandler) obtainNewToken(apiHandler apihandler.APIHandler, http } else { err = fmt.Errorf("no valid credentials provided. Unable to obtain a token") h.Logger.Error("Authentication method not supported", zap.String("AuthMethod", h.AuthMethod)) + return err // Return the error immediately } if err == nil { - h.Logger.Info("Successfully obtained new token", zap.String("AuthMethod", h.AuthMethod)) break } @@ -78,7 +78,12 @@ func (h *AuthTokenHandler) obtainNewToken(apiHandler apihandler.APIHandler, http backoff *= 2 } - return err + if err != nil { + h.Logger.Error("Failed to obtain new token after all attempts", zap.Error(err)) + return err + } + + return nil } // refreshTokenIfNeeded refreshes the token if it's close to expiration.