Skip to content

Commit

Permalink
Print login required output when token is expired (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahlunar committed Jan 3, 2024
1 parent 2ec94bc commit e5c3975
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/http/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var (
ErrLoginRequired = errors.New("login required")
ErrTokenExpired = errors.New("oauth2: token expired and refresh token is not set")
)

type UserAuthenticator struct {
Expand Down
7 changes: 7 additions & 0 deletions internal/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/http"
"net/url"
"strings"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -87,6 +88,12 @@ func (c *Client) Do(method string, path string, requestBody, responseBody interf
if stderrors.As(err, &dnsError) || (stderrors.As(err, &urlError) && stderrors.Is(err, io.EOF)) {
return connectivityError
}

// Checking on the string as errors.Is fails to match on our ErrTokenExpired which is a copy of the internal oauth2 error from golang/x/oauth2 package.
if strings.Contains(err.Error(), ErrTokenExpired.Error()) {
return fmt.Errorf("%w: %w", ErrLoginRequired, err)
}

return &ErrorResponse{
Message: err.Error(),
ID: id.String(),
Expand Down

0 comments on commit e5c3975

Please sign in to comment.