Skip to content

Commit f51c104

Browse files
authored
Merge pull request #163 from cli/handle_205
fix: handle HTTP status 205 properly
2 parents 4d3e492 + 0e44f09 commit f51c104

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pkg/api/rest_client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ func (c *RESTClient) DoWithContext(ctx context.Context, method string, path stri
100100
if resp.StatusCode == http.StatusNoContent {
101101
return nil
102102
}
103+
104+
if resp.StatusCode == http.StatusResetContent {
105+
return nil
106+
}
107+
103108
defer resp.Body.Close()
104109

105110
b, err := io.ReadAll(resp.Body)

pkg/api/rest_client_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,24 @@ func TestRESTClientPatch(t *testing.T) {
304304
assert.True(t, gock.IsDone(), printPendingMocks(gock.Pending()))
305305
}
306306

307+
func TestRESTClientPatchStatus205(t *testing.T) {
308+
t.Cleanup(gock.Off)
309+
gock.New("https://api.github.com").
310+
Patch("/some/path/here").
311+
BodyString(`{}`).
312+
Reply(205).
313+
BodyString("")
314+
client, _ := NewRESTClient(ClientOptions{
315+
Host: "github.com",
316+
AuthToken: "token",
317+
Transport: http.DefaultTransport,
318+
})
319+
r := bytes.NewReader([]byte(`{}`))
320+
err := client.Patch("some/path/here", r, nil)
321+
assert.NoError(t, err)
322+
assert.True(t, gock.IsDone(), printPendingMocks(gock.Pending()))
323+
}
324+
307325
func TestRESTClientPost(t *testing.T) {
308326
t.Cleanup(gock.Off)
309327
gock.New("https://api.github.com").

0 commit comments

Comments
 (0)