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

Add awsQueryCompatible error code translation support #4597

Merged
merged 14 commits into from
Dec 28, 2022
Prev Previous commit
Next Next commit
Fix query header population in tests
  • Loading branch information
eddy-aws committed Oct 24, 2022
commit 039e58b0f3ac2f973484fc99ff1e3d76218e7e11
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ func TestAWSQuery(t *testing.T) {
io.Reader
Len() int
}
headers http.Header
headers map[string]string
expectErrorCode string
}{
"when header is present": {
statusCode: 500,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`),
expectErrorCode: "AWS.SimpleQueueService.QueueDeletedRecently",
headers: http.Header{"x-amzn-query-error": []string{"AWS.SimpleQueueService.QueueDeletedRecently;Sender"}},
headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently;Sender"},
},
"for unmodlled error code": {
eddy-aws marked this conversation as resolved.
Show resolved Hide resolved
statusCode: 400,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#AccessDeniedException", "message":"Some user-visible message"}`),
expectErrorCode: "AccessDenied",
headers: http.Header{"x-amzn-query-error": []string{"AccessDenied;Sender"}},
headers: map[string]string{"x-amzn-query-error": "AccessDenied;Sender"},
},
"when header is not present": {
statusCode: 400,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#AccessDeniedException", "message":"Some user-visible message"}`),
expectErrorCode: "AccessDeniedException",
headers: http.Header{},
headers: map[string]string{},
},
"when header is nil": {
statusCode: 400,
Expand All @@ -56,7 +56,7 @@ func TestAWSQuery(t *testing.T) {
statusCode: 500,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`),
expectErrorCode: "QueueDeletedRecently",
eddy-aws marked this conversation as resolved.
Show resolved Hide resolved
headers: http.Header{"x-amzn-query-error": []string{"AWS.SimpleQueueService.QueueDeletedRecently-Sender"}},
headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently-Sender"},
},
}

Expand All @@ -77,7 +77,15 @@ func TestAWSQuery(t *testing.T) {
}
return int64(c.responseBody.Len())
}(),
Header: c.headers,
Header: func() http.Header {
h := http.Header{}
if c.headers != nil {
for key, value := range c.headers {
h.Set(key, value)
}
}
return h
}(),
Body: ioutil.NopCloser(c.responseBody),
}
},
Expand Down
22 changes: 10 additions & 12 deletions private/protocol/jsonrpc/unmarshal_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,16 @@ func (u *UnmarshalTypedError) UnmarshalError(
code := codeParts[len(codeParts)-1]
eddy-aws marked this conversation as resolved.
Show resolved Hide resolved
msg := jsonErr.Message

if (resp.Header != nil) {
queryCodeHeader := resp.Header[awsQueryError]
if len(queryCodeHeader) > 0 {
queryCodeParts := strings.Split(queryCodeHeader[0], ";")
if queryCodeParts != nil && len(queryCodeParts) == 2 {
return awserr.NewRequestFailure(
awserr.New(queryCodeParts[0], msg, nil),
respMeta.StatusCode,
respMeta.RequestID,
), nil
}
}
queryCodeHeader := resp.Header.Get(awsQueryError)
if queryCodeHeader != "" {
queryCodeParts := strings.Split(queryCodeHeader, ";")
if queryCodeParts != nil && len(queryCodeParts) == 2 {
return awserr.NewRequestFailure(
awserr.New(queryCodeParts[0], msg, nil),
respMeta.StatusCode,
respMeta.RequestID,
), nil
}
}

if fn, ok := u.exceptions[code]; ok {
Expand Down