peridot/vendor/github.com/aws/aws-sdk-go/service/s3/statusok_error.go

48 lines
1.2 KiB
Go
Raw Normal View History

2022-07-07 20:11:50 +00:00
package s3
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/internal/sdkio"
)
2022-11-04 02:21:49 +00:00
func copyMultipartStatusOKUnmarshalError(r *request.Request) {
2022-07-07 20:11:50 +00:00
b, err := ioutil.ReadAll(r.HTTPResponse.Body)
2022-11-04 02:21:49 +00:00
r.HTTPResponse.Body.Close()
2022-07-07 20:11:50 +00:00
if err != nil {
r.Error = awserr.NewRequestFailure(
awserr.New(request.ErrCodeSerialization, "unable to read response body", err),
r.HTTPResponse.StatusCode,
r.RequestID,
)
2022-11-04 02:21:49 +00:00
// Note, some middleware later in the stack like restxml.Unmarshal expect a valid, non-closed Body
// even in case of an error, so we replace it with an empty Reader.
r.HTTPResponse.Body = ioutil.NopCloser(bytes.NewBuffer(nil))
2022-07-07 20:11:50 +00:00
return
}
2022-11-04 02:21:49 +00:00
2022-07-07 20:11:50 +00:00
body := bytes.NewReader(b)
r.HTTPResponse.Body = ioutil.NopCloser(body)
defer body.Seek(0, sdkio.SeekStart)
unmarshalError(r)
if err, ok := r.Error.(awserr.Error); ok && err != nil {
if err.Code() == request.ErrCodeSerialization &&
err.OrigErr() != io.EOF {
r.Error = nil
return
}
// if empty payload
if err.OrigErr() == io.EOF {
r.HTTPResponse.StatusCode = http.StatusInternalServerError
} else {
r.HTTPResponse.StatusCode = http.StatusServiceUnavailable
}
}
}