Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(oauth): Show network issue separately for auth errors #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -181,10 +182,24 @@ 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 {
return nil, err
}
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)
}
Loading