Better handle nil responses in S3 backend, also a case where error wasn't checked

This commit is contained in:
Jeff Mitchell 2016-04-22 18:07:59 +00:00
parent 51a97717db
commit e5c31d66a2
1 changed files with 9 additions and 1 deletions

View File

@ -120,7 +120,6 @@ func (s *S3Backend) Get(key string) (*Entry, error) {
Bucket: aws.String(s.bucket),
Key: aws.String(key),
})
if awsErr, ok := err.(awserr.RequestFailure); ok {
// Return nil on 404s, error on anything else
if awsErr.StatusCode() == 404 {
@ -129,6 +128,12 @@ func (s *S3Backend) Get(key string) (*Entry, error) {
return nil, err
}
}
if err != nil {
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("got nil response from S3 but no error")
}
data := make([]byte, *resp.ContentLength)
_, err = io.ReadFull(resp.Body, data)
@ -172,6 +177,9 @@ func (s *S3Backend) List(prefix string) ([]string, error) {
if err != nil {
return nil, err
}
if resp == nil {
return nil, fmt.Errorf("nil response from S3 but no error")
}
keys := []string{}
for _, key := range resp.Contents {