diff --git a/private/protocol/ec2query/unmarshal.go b/private/protocol/ec2query/unmarshal.go
index c42b04a8d55..0be67be5907 100644
--- a/private/protocol/ec2query/unmarshal.go
+++ b/private/protocol/ec2query/unmarshal.go
@@ -4,6 +4,7 @@ package ec2query
import (
"encoding/xml"
+ "strings"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
@@ -70,7 +71,7 @@ func UnmarshalError(r *request.Request) {
}
r.Error = awserr.NewRequestFailure(
- awserr.New(respErr.Code, respErr.Message, nil),
+ awserr.New(strings.TrimSpace(respErr.Code), strings.TrimSpace(respErr.Message), nil),
r.HTTPResponse.StatusCode,
respErr.RequestID,
)
diff --git a/private/protocol/ec2query/unmarshal_error_test.go b/private/protocol/ec2query/unmarshal_error_test.go
index ad83dc4a354..80734be5e6d 100644
--- a/private/protocol/ec2query/unmarshal_error_test.go
+++ b/private/protocol/ec2query/unmarshal_error_test.go
@@ -40,6 +40,30 @@ func TestUnmarshalError(t *testing.T) {
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
+ "ErrorResponse with spaces": {
+ Request: &request.Request{
+ HTTPResponse: &http.Response{
+ StatusCode: 400,
+ Header: http.Header{},
+ Body: ioutil.NopCloser(strings.NewReader(
+ `
+
+
+
+ codeAbc
+
+
+ msg123
+
+
+
+ reqID123
+ `)),
+ },
+ },
+ Code: "codeAbc", Msg: "msg123",
+ Status: 400, ReqID: "reqID123",
+ },
"unknown tag": {
Request: &request.Request{
HTTPResponse: &http.Response{
diff --git a/private/protocol/query/unmarshal_error.go b/private/protocol/query/unmarshal_error.go
index 831b0110c54..2c0cbba909b 100644
--- a/private/protocol/query/unmarshal_error.go
+++ b/private/protocol/query/unmarshal_error.go
@@ -3,6 +3,7 @@ package query
import (
"encoding/xml"
"fmt"
+ "strings"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
@@ -62,7 +63,7 @@ func UnmarshalError(r *request.Request) {
}
r.Error = awserr.NewRequestFailure(
- awserr.New(respErr.Code, respErr.Message, nil),
+ awserr.New(strings.TrimSpace(respErr.Code), strings.TrimSpace(respErr.Message), nil),
r.HTTPResponse.StatusCode,
reqID,
)
diff --git a/private/protocol/query/unmarshal_error_test.go b/private/protocol/query/unmarshal_error_test.go
index 34bf1a56486..7e317004d5c 100644
--- a/private/protocol/query/unmarshal_error_test.go
+++ b/private/protocol/query/unmarshal_error_test.go
@@ -37,6 +37,27 @@ func TestUnmarshalError(t *testing.T) {
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
+ "ErrorResponse with spaces": {
+ Request: &request.Request{
+ HTTPResponse: &http.Response{
+ StatusCode: 400,
+ Header: http.Header{},
+ Body: ioutil.NopCloser(strings.NewReader(
+ `
+
+
+ codeAbc
+
+ msg123
+
+
+ reqID123
+ `)),
+ },
+ },
+ Code: "codeAbc", Msg: "msg123",
+ Status: 400, ReqID: "reqID123",
+ },
"ServiceUnavailableException": {
Request: &request.Request{
HTTPResponse: &http.Response{