Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

private/protocol/query: Fix deserialize error code with spaces #4525

Merged
merged 1 commit into from Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion private/protocol/ec2query/unmarshal.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
Expand Down
24 changes: 24 additions & 0 deletions private/protocol/ec2query/unmarshal_error_test.go
Expand Up @@ -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(
`<Response>
<Errors>
<Error>
<Code>
codeAbc
</Code>
<Message>
msg123
</Message>
</Error>
</Errors>
<RequestID>reqID123</RequestID>
</Response>`)),
},
},
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
"unknown tag": {
Request: &request.Request{
HTTPResponse: &http.Response{
Expand Down
3 changes: 2 additions & 1 deletion private/protocol/query/unmarshal_error.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
)
Expand Down
21 changes: 21 additions & 0 deletions private/protocol/query/unmarshal_error_test.go
Expand Up @@ -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(
`<ErrorResponse>
<Error>
<Code>
codeAbc
</Code><Message>
msg123
</Message>
</Error>
<RequestId>reqID123</RequestId>
</ErrorResponse>`)),
},
},
Code: "codeAbc", Msg: "msg123",
Status: 400, ReqID: "reqID123",
},
"ServiceUnavailableException": {
Request: &request.Request{
HTTPResponse: &http.Response{
Expand Down