Skip to content

Commit

Permalink
CLOUDP-118714 add IsTimeoutErr func (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibulca authored May 6, 2022
1 parent 33f2542 commit 0a87693
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions auth/device_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const authExpiredError = "DEVICE_AUTHORIZATION_EXPIRED"

// DeviceCode holds information about the authorization-in-progress.
type DeviceCode struct {
UserCode string `json:"user_code"` // UserCode is the code presented to users
Expand Down Expand Up @@ -146,3 +148,8 @@ func (c Config) RevokeToken(ctx context.Context, token, tokenTypeHint string) (*

return c.Do(ctx, req, nil)
}

func IsTimeoutErr(err error) bool {
var target *atlas.ErrorResponse
return errors.Is(err, ErrTimeout) || (errors.As(err, &target) && target.ErrorCode == authExpiredError)
}

0 comments on commit 0a87693

Please sign in to comment.