Skip to content

Commit 70e0ea7

Browse files
authored
Add error type for blocked host (#30)
1 parent 6a10587 commit 70e0ea7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func (e *APIError) Unwrap() error {
8181

8282
var ErrInvalidCredentials = fmt.Errorf("invalid credentials")
8383
var ErrInvalidCode = fmt.Errorf("invalid enrollment code")
84+
var ErrHostBlocked = fmt.Errorf("host is blocked")
8485

8586
type ConfigMeta struct {
8687
Org ConfigOrg
@@ -181,11 +182,16 @@ func (c *Client) Enroll(ctx context.Context, logger logrus.FieldLogger, code str
181182
return nil, nil, nil, nil, &APIError{e: fmt.Errorf("error decoding JSON response: %s\nbody: %s", err, b), ReqID: reqID}
182183
}
183184

184-
// Check for *only* an "invalid code" error returned by the API
185185
if len(r.Errors) == 1 {
186+
// Check for *only* an "invalid code" error returned by the API
186187
if err := r.Errors[0]; err.Path == "code" && err.Code == "ERR_INVALID_VALUE" {
187188
return nil, nil, nil, nil, &APIError{e: ErrInvalidCode, ReqID: reqID}
188189
}
190+
191+
// Check for *only* a blocked host error returned by the API
192+
if err := r.Errors[0]; err.Path == "" && err.Code == "ERR_HOST_BLOCKED" {
193+
return nil, nil, nil, nil, &APIError{e: ErrHostBlocked, ReqID: reqID}
194+
}
189195
}
190196

191197
// Check for any errors returned by the API

0 commit comments

Comments
 (0)