statusok_error.go 905 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package s3
  2. import (
  3. "bytes"
  4. "io/ioutil"
  5. "net/http"
  6. "github.com/aws/aws-sdk-go/aws/awserr"
  7. "github.com/aws/aws-sdk-go/aws/request"
  8. "github.com/aws/aws-sdk-go/internal/sdkio"
  9. )
  10. func copyMultipartStatusOKUnmarhsalError(r *request.Request) {
  11. b, err := ioutil.ReadAll(r.HTTPResponse.Body)
  12. if err != nil {
  13. r.Error = awserr.NewRequestFailure(
  14. awserr.New("SerializationError", "unable to read response body", err),
  15. r.HTTPResponse.StatusCode,
  16. r.RequestID,
  17. )
  18. return
  19. }
  20. body := bytes.NewReader(b)
  21. r.HTTPResponse.Body = ioutil.NopCloser(body)
  22. defer body.Seek(0, sdkio.SeekStart)
  23. if body.Len() == 0 {
  24. // If there is no body don't attempt to parse the body.
  25. return
  26. }
  27. unmarshalError(r)
  28. if err, ok := r.Error.(awserr.Error); ok && err != nil {
  29. if err.Code() == "SerializationError" {
  30. r.Error = nil
  31. return
  32. }
  33. r.HTTPResponse.StatusCode = http.StatusServiceUnavailable
  34. }
  35. }