Skip to content

Commit b1f7dec

Browse files
committed
add better errors for authn failures
1 parent 3fee633 commit b1f7dec

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

client.go

+10
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ func (c *Client) send(req *http.Request, model interface{}) (*Response, error) {
374374

375375
// Handle certain license auth error codes so that we emit helpful errors
376376
switch {
377+
case code == ErrorCodeTokenNotAllowed:
378+
return response, ErrTokenNotAllowed
379+
case code == ErrorCodeTokenFormatInvalid:
380+
return response, ErrTokenFormatInvalid
381+
case code == ErrorCodeTokenInvalid:
382+
return response, ErrTokenInvalid
383+
case code == ErrorCodeTokenExpired:
384+
return response, ErrTokenExpired
385+
case code == ErrorCodeLicenseNotAllowed:
386+
return response, ErrLicenseNotAllowed
377387
case code == ErrorCodeLicenseSuspended:
378388
return response, ErrLicenseSuspended
379389
case code == ErrorCodeLicenseExpired:

errors.go

+9
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ type ErrorCode string
1212
const (
1313
ErrorCodeEnvironmentInvalid ErrorCode = "ENVIRONMENT_INVALID"
1414
ErrorCodeEnvironmentNotSupported ErrorCode = "ENVIRONMENT_NOT_SUPPORTED"
15+
ErrorCodeTokenFormatInvalid ErrorCode = "TOKEN_FORMAT_INVALID"
1516
ErrorCodeTokenInvalid ErrorCode = "TOKEN_INVALID"
17+
ErrorCodeTokenExpired ErrorCode = "TOKEN_EXPIRED"
18+
ErrorCodeTokenNotAllowed ErrorCode = "TOKEN_NOT_ALLOWED"
1619
ErrorCodeLicenseInvalid ErrorCode = "LICENSE_INVALID"
1720
ErrorCodeLicenseExpired ErrorCode = "LICENSE_EXPIRED"
1821
ErrorCodeLicenseSuspended ErrorCode = "LICENSE_SUSPENDED"
22+
ErrorCodeLicenseNotAllowed ErrorCode = "LICENSE_NOT_ALLOWED"
1923
ErrorCodeFingerprintTaken ErrorCode = "FINGERPRINT_TAKEN"
2024
ErrorCodeMachineLimitExceeded ErrorCode = "MACHINE_LIMIT_EXCEEDED"
2125
ErrorCodeProcessLimitExceeded ErrorCode = "MACHINE_PROCESS_LIMIT_EXCEEDED"
@@ -140,6 +144,7 @@ var (
140144
ErrLicenseKeyMissing = errors.New("license key is missing")
141145
ErrLicenseKeyNotGenuine = errors.New("license key is not genuine")
142146
ErrLicenseNotActivated = errors.New("license is not activated")
147+
ErrLicenseNotAllowed = errors.New("license authentication is not allowed by policy")
143148
ErrLicenseExpired = errors.New("license is expired")
144149
ErrLicenseSuspended = errors.New("license is suspended")
145150
ErrLicenseTooManyMachines = errors.New("license has too many machines")
@@ -152,5 +157,9 @@ var (
152157
ErrLicenseFileNotGenuine = errors.New("license file is not genuine")
153158
ErrLicenseFileExpired = errors.New("license file is expired")
154159
ErrLicenseFileSecretMissing = errors.New("license file secret is missing")
160+
ErrTokenNotAllowed = errors.New("token authentication is not allowed by policy")
161+
ErrTokenFormatInvalid = errors.New("token format is invalid")
162+
ErrTokenInvalid = errors.New("token is invalid")
163+
ErrTokenExpired = errors.New("token is expired")
155164
ErrSystemClockUnsynced = errors.New("system clock is out of sync")
156165
)

0 commit comments

Comments
 (0)