Skip to content

Commit

Permalink
add better errors for authn failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jun 7, 2024
1 parent a8b0460 commit b920cd2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ func (c *Client) send(req *http.Request, model interface{}) (*Response, error) {

// Handle certain license auth error codes so that we emit helpful errors
switch {
case code == ErrorCodeTokenNotAllowed:
return response, ErrTokenNotAllowed
case code == ErrorCodeTokenFormatInvalid:
return response, ErrTokenFormatInvalid
case code == ErrorCodeTokenInvalid:
return response, ErrTokenInvalid
case code == ErrorCodeTokenExpired:
return response, ErrTokenExpired
case code == ErrorCodeLicenseNotAllowed:
return response, ErrLicenseNotAllowed
case code == ErrorCodeLicenseSuspended:
return response, ErrLicenseSuspended
case code == ErrorCodeLicenseExpired:
Expand Down
9 changes: 9 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ type ErrorCode string
const (
ErrorCodeEnvironmentInvalid ErrorCode = "ENVIRONMENT_INVALID"
ErrorCodeEnvironmentNotSupported ErrorCode = "ENVIRONMENT_NOT_SUPPORTED"
ErrorCodeTokenFormatInvalid ErrorCode = "TOKEN_FORMAT_INVALID"
ErrorCodeTokenInvalid ErrorCode = "TOKEN_INVALID"
ErrorCodeTokenExpired ErrorCode = "TOKEN_EXPIRED"
ErrorCodeTokenNotAllowed ErrorCode = "TOKEN_NOT_ALLOWED"
ErrorCodeLicenseInvalid ErrorCode = "LICENSE_INVALID"
ErrorCodeLicenseExpired ErrorCode = "LICENSE_EXPIRED"
ErrorCodeLicenseSuspended ErrorCode = "LICENSE_SUSPENDED"
ErrorCodeLicenseNotAllowed ErrorCode = "LICENSE_NOT_ALLOWED"
ErrorCodeFingerprintTaken ErrorCode = "FINGERPRINT_TAKEN"
ErrorCodeMachineLimitExceeded ErrorCode = "MACHINE_LIMIT_EXCEEDED"
ErrorCodeProcessLimitExceeded ErrorCode = "MACHINE_PROCESS_LIMIT_EXCEEDED"
Expand Down Expand Up @@ -140,6 +144,7 @@ var (
ErrLicenseKeyMissing = errors.New("license key is missing")
ErrLicenseKeyNotGenuine = errors.New("license key is not genuine")
ErrLicenseNotActivated = errors.New("license is not activated")
ErrLicenseNotAllowed = errors.New("license authentication is not allowed by policy")
ErrLicenseExpired = errors.New("license is expired")
ErrLicenseSuspended = errors.New("license is suspended")
ErrLicenseTooManyMachines = errors.New("license has too many machines")
Expand All @@ -152,5 +157,9 @@ var (
ErrLicenseFileNotGenuine = errors.New("license file is not genuine")
ErrLicenseFileExpired = errors.New("license file is expired")
ErrLicenseFileSecretMissing = errors.New("license file secret is missing")
ErrTokenNotAllowed = errors.New("token authentication is not allowed by policy")
ErrTokenFormatInvalid = errors.New("token format is invalid")
ErrTokenInvalid = errors.New("token is invalid")
ErrTokenExpired = errors.New("token is expired")
ErrSystemClockUnsynced = errors.New("system clock is out of sync")
)

0 comments on commit b920cd2

Please sign in to comment.