Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04afb88

Browse files
authored
fix: return a more sophisticated error for device failure on 429 (#11554)
* fix: return a more sophisticated error for device failure on 429
1 parentb1d53a6 commit04afb88

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

‎coderd/externalauth/externalauth.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,14 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.ExternalAut
321321
}
322322
err=json.NewDecoder(resp.Body).Decode(&r)
323323
iferr!=nil {
324-
returnnil,err
324+
// Some status codes do not return json payloads, and we should
325+
// return a better error.
326+
switchresp.StatusCode {
327+
casehttp.StatusTooManyRequests:
328+
returnnil,fmt.Errorf("rate limit hit, unable to authorize device. please try again later")
329+
default:
330+
returnnil,err
331+
}
325332
}
326333
ifr.ErrorDescription!="" {
327334
returnnil,xerrors.New(r.ErrorDescription)

‎coderd/externalauth_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,28 @@ func TestExternalAuthDevice(t *testing.T) {
279279
require.NoError(t,err)
280280
require.True(t,auth.Authenticated)
281281
})
282+
t.Run("TooManyRequests",func(t*testing.T) {
283+
t.Parallel()
284+
srv:=httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
285+
w.WriteHeader(http.StatusTooManyRequests)
286+
// Github returns an html payload for this error.
287+
_,_=w.Write([]byte(`Please wait a few minutes before you try again`))
288+
}))
289+
defersrv.Close()
290+
client:=coderdtest.New(t,&coderdtest.Options{
291+
ExternalAuthConfigs: []*externalauth.Config{{
292+
ID:"test",
293+
DeviceAuth:&externalauth.DeviceAuth{
294+
ClientID:"test",
295+
CodeURL:srv.URL,
296+
Scopes: []string{"repo"},
297+
},
298+
}},
299+
})
300+
coderdtest.CreateFirstUser(t,client)
301+
_,err:=client.ExternalAuthDeviceByID(context.Background(),"test")
302+
require.ErrorContains(t,err,"rate limit hit")
303+
})
282304
}
283305

284306
// nolint:bodyclose

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp