From d0bfdabf6b90bdc1bd67358a29f5a5b18b5d7e60 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Thu, 24 Apr 2025 17:15:17 +0300 Subject: [PATCH] refactor(auth): early returns in cred listener --- auth/reauth_credentials_listener.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/auth/reauth_credentials_listener.go b/auth/reauth_credentials_listener.go index 12eb2956..40076a0b 100644 --- a/auth/reauth_credentials_listener.go +++ b/auth/reauth_credentials_listener.go @@ -14,22 +14,24 @@ type ReAuthCredentialsListener struct { // It calls the reAuth function with the new credentials. // If the reAuth function returns an error, it calls the onErr function with the error. func (c *ReAuthCredentialsListener) OnNext(credentials Credentials) { - if c.reAuth != nil { - err := c.reAuth(credentials) - if err != nil { - if c.onErr != nil { - c.onErr(err) - } - } + if c.reAuth == nil { + return + } + + err := c.reAuth(credentials) + if err != nil { + c.OnError(err) } } // OnError is called when an error occurs. // It can be called from both the credentials provider and the reAuth function. func (c *ReAuthCredentialsListener) OnError(err error) { - if c.onErr != nil { - c.onErr(err) + if c.onErr == nil { + return } + + c.onErr(err) } // NewReAuthCredentialsListener creates a new ReAuthCredentialsListener.