Skip to content

Commit d0bfdab

Browse files
committed
refactor(auth): early returns in cred listener
1 parent 5f91e66 commit d0bfdab

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

auth/reauth_credentials_listener.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ type ReAuthCredentialsListener struct {
1414
// It calls the reAuth function with the new credentials.
1515
// If the reAuth function returns an error, it calls the onErr function with the error.
1616
func (c *ReAuthCredentialsListener) OnNext(credentials Credentials) {
17-
if c.reAuth != nil {
18-
err := c.reAuth(credentials)
19-
if err != nil {
20-
if c.onErr != nil {
21-
c.onErr(err)
22-
}
23-
}
17+
if c.reAuth == nil {
18+
return
19+
}
20+
21+
err := c.reAuth(credentials)
22+
if err != nil {
23+
c.OnError(err)
2424
}
2525
}
2626

2727
// OnError is called when an error occurs.
2828
// It can be called from both the credentials provider and the reAuth function.
2929
func (c *ReAuthCredentialsListener) OnError(err error) {
30-
if c.onErr != nil {
31-
c.onErr(err)
30+
if c.onErr == nil {
31+
return
3232
}
33+
34+
c.onErr(err)
3335
}
3436

3537
// NewReAuthCredentialsListener creates a new ReAuthCredentialsListener.

0 commit comments

Comments
 (0)