Skip to content

Commit

Permalink
Merge pull request #160 from GeoNet/s3head-fix
Browse files Browse the repository at this point in the history
chore: fix s3 headobject not found checking
  • Loading branch information
sue-h-gns authored Mar 7, 2024
2 parents 3fef5b3 + a2e567d commit a00bd95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,15 @@ func (s *S3) GetMeta(bucket, key, version string) (Meta, error) {

res, err := s.client.HeadObject(context.TODO(), &input)
if err != nil {
var nf *types.NotFound
if errors.As(err, &nf) {
return Meta{}, nil
if err != nil {
var ae smithy.APIError
if errors.As(err, &ae) {
if ae.ErrorCode() == "NotFound" {
return Meta{}, nil
}
}
return Meta{}, err
}
return Meta{}, err
}

return res.Metadata, nil
Expand Down
7 changes: 7 additions & 0 deletions aws/s3/s3_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ func TestS3GetMeta(t *testing.T) {
// ASSERT
assert.Nil(t, err)
assert.Equal(t, testMetaValue, meta[testMetaKey])

// for non existing object, we want an empty result instead of not found error
meta, err = client.GetMeta(testBucket, fmt.Sprintf("%s.%d", testObjectKey, time.Now().Unix()), "")

// ASSERT
assert.Nil(t, err)
assert.Empty(t, meta)
}

func TestS3GetContentSizeTime(t *testing.T) {
Expand Down

0 comments on commit a00bd95

Please sign in to comment.