Skip to content

Commit

Permalink
Fix status code handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Dec 24, 2021
1 parent d72d86a commit 8413b3f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (p *Client) Write(ctx context.Context, req *WriteRequest, options ...WriteO
}
defer httpResp.Body.Close()

if st := httpResp.StatusCode; st != http.StatusOK {
if st := httpResp.StatusCode; st/100 != 2 {
msg, _ := ioutil.ReadAll(httpResp.Body)
return nil, &WriteError{
err: fmt.Errorf("promwrite: expected status %d, got %d: %s", http.StatusOK, st, string(msg)),
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestClient(t *testing.T) {
r.NoError(err)
receivedWriteRequest <- parsed
receivedHeaders <- req.Header
w.WriteHeader(http.StatusOK)
w.WriteHeader(http.StatusAccepted)
}))
defer srv.Close()

Expand Down

0 comments on commit 8413b3f

Please sign in to comment.