fix: return a more sophisticated error for device failure on 429 (#11554)

* fix: return a more sophisticated error for device failure on 429
This commit is contained in:
Steven Masley
2024-01-10 11:29:44 -06:00
committed by GitHub
parent b1d53a68c2
commit 04afb88e6f
2 changed files with 30 additions and 1 deletions

View File

@ -321,7 +321,14 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAut
}
err = json.NewDecoder(resp.Body).Decode(&r)
if err != nil {
return nil, err
// Some status codes do not return json payloads, and we should
// return a better error.
switch resp.StatusCode {
case http.StatusTooManyRequests:
return nil, fmt.Errorf("rate limit hit, unable to authorize device. please try again later")
default:
return nil, err
}
}
if r.ErrorDescription != "" {
return nil, xerrors.New(r.ErrorDescription)