From 8b2a190cd93ffed72f25565a609ce9923ff617f6 Mon Sep 17 00:00:00 2001 From: Sanyam Khurana Date: Fri, 22 Nov 2024 06:47:43 +0530 Subject: [PATCH] fix(oauth): Show network issue separately for auth errors --- auth/oauth.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/auth/oauth.go b/auth/oauth.go index 03fd1f0..b5e5a98 100644 --- a/auth/oauth.go +++ b/auth/oauth.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "net" "net/http" "strings" "time" @@ -181,6 +182,9 @@ func GetTokens() (*Tokens, error) { } tokens, err = Oauth.RefreshTokens(tokens) if err != nil { + if isNetworkError(err) { + return nil, fmt.Errorf("network issue: %w", err) + } return nil, fmt.Errorf("%s: %w", TokenRefreshErr, err) } if err = tokens.WriteToCache(); err != nil { @@ -188,3 +192,14 @@ func GetTokens() (*Tokens, error) { } return tokens, nil } + +func isNetworkError(err error) bool { + var netErr net.Error + if errors.As(err, &netErr) { + return true + } + + // Handle DNS resolution errors directly + var dnsErr *net.DNSError + return errors.As(err, &dnsErr) +}