diff options
Diffstat (limited to 'vendor/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go')
-rw-r--r-- | vendor/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/vendor/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go b/vendor/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go index 1db7e13..5b63fac 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go +++ b/vendor/github.com/aws/aws-sdk-go/service/s3/unmarshal_error.go | |||
@@ -11,6 +11,7 @@ import ( | |||
11 | "github.com/aws/aws-sdk-go/aws" | 11 | "github.com/aws/aws-sdk-go/aws" |
12 | "github.com/aws/aws-sdk-go/aws/awserr" | 12 | "github.com/aws/aws-sdk-go/aws/awserr" |
13 | "github.com/aws/aws-sdk-go/aws/request" | 13 | "github.com/aws/aws-sdk-go/aws/request" |
14 | "github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil" | ||
14 | ) | 15 | ) |
15 | 16 | ||
16 | type xmlErrorResponse struct { | 17 | type xmlErrorResponse struct { |
@@ -42,29 +43,34 @@ func unmarshalError(r *request.Request) { | |||
42 | return | 43 | return |
43 | } | 44 | } |
44 | 45 | ||
45 | var errCode, errMsg string | ||
46 | |||
47 | // Attempt to parse error from body if it is known | 46 | // Attempt to parse error from body if it is known |
48 | resp := &xmlErrorResponse{} | 47 | var errResp xmlErrorResponse |
49 | err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp) | 48 | err := xmlutil.UnmarshalXMLError(&errResp, r.HTTPResponse.Body) |
50 | if err != nil && err != io.EOF { | 49 | if err == io.EOF { |
51 | errCode = "SerializationError" | 50 | // Only capture the error if an unmarshal error occurs that is not EOF, |
52 | errMsg = "failed to decode S3 XML error response" | 51 | // because S3 might send an error without a error message which causes |
53 | } else { | 52 | // the XML unmarshal to fail with EOF. |
54 | errCode = resp.Code | ||
55 | errMsg = resp.Message | ||
56 | err = nil | 53 | err = nil |
57 | } | 54 | } |
55 | if err != nil { | ||
56 | r.Error = awserr.NewRequestFailure( | ||
57 | awserr.New(request.ErrCodeSerialization, | ||
58 | "failed to unmarshal error message", err), | ||
59 | r.HTTPResponse.StatusCode, | ||
60 | r.RequestID, | ||
61 | ) | ||
62 | return | ||
63 | } | ||
58 | 64 | ||
59 | // Fallback to status code converted to message if still no error code | 65 | // Fallback to status code converted to message if still no error code |
60 | if len(errCode) == 0 { | 66 | if len(errResp.Code) == 0 { |
61 | statusText := http.StatusText(r.HTTPResponse.StatusCode) | 67 | statusText := http.StatusText(r.HTTPResponse.StatusCode) |
62 | errCode = strings.Replace(statusText, " ", "", -1) | 68 | errResp.Code = strings.Replace(statusText, " ", "", -1) |
63 | errMsg = statusText | 69 | errResp.Message = statusText |
64 | } | 70 | } |
65 | 71 | ||
66 | r.Error = awserr.NewRequestFailure( | 72 | r.Error = awserr.NewRequestFailure( |
67 | awserr.New(errCode, errMsg, err), | 73 | awserr.New(errResp.Code, errResp.Message, err), |
68 | r.HTTPResponse.StatusCode, | 74 | r.HTTPResponse.StatusCode, |
69 | r.RequestID, | 75 | r.RequestID, |
70 | ) | 76 | ) |