Skip to content

Commit

Permalink
client: fix HeadObject error response
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Mar 22, 2024
1 parent c148336 commit 1cb3ac1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions internal/test/e2e/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func TestS3Basic(t *testing.T) {
t.Fatal("unexpected ETag:", info.ETag)
}

// stat object that doesn't exist
_, err = s3.StatObject(context.Background(), bucket, "nonexistent", minio.StatObjectOptions{})
if err == nil || !strings.Contains(err.Error(), "The specified key does not exist") {
t.Fatal(err)
}

// add another bucket
tt.OK(s3.MakeBucket(context.Background(), bucket+"2", minio.MakeBucketOptions{}))

Expand Down
8 changes: 6 additions & 2 deletions worker/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,13 @@ func (c *Client) HeadObject(ctx context.Context, bucket, path string, opts api.H
return nil, err
}
if resp.StatusCode != 200 && resp.StatusCode != 206 {
err, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()
return nil, errors.New(string(err))
switch resp.StatusCode {
case http.StatusNotFound:
return nil, api.ErrObjectNotFound
default:
return nil, errors.New(http.StatusText(resp.StatusCode))
}
}

head, err := parseObjectResponseHeaders(resp.Header)
Expand Down

0 comments on commit 1cb3ac1

Please sign in to comment.