Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eddy-aws committed Dec 16, 2022
1 parent ef33e60 commit 9adcdc0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"awsQueryCompatible": {

},
"endpointPrefix":"awsquerycompatible",
"endpointPrefix":"awsqc-exampleendpoint",
"jsonVersion":"1.1",
"protocol":"json",
"serviceAbbreviation":"AwsQueryCompatible",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func TestAWSQuery(t *testing.T) {
expectErrorCode string
}{
"when header is present": {
statusCode: 500,
statusCode: 400,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`),
expectErrorCode: "AWS.SimpleQueueService.QueueDeletedRecently",
headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently;Sender"},
},
"for unmodlled error code": {
"for unmodeled error code": {
statusCode: 400,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#AccessDeniedException", "message":"Some user-visible message"}`),
expectErrorCode: "AccessDenied",
Expand All @@ -53,7 +53,7 @@ func TestAWSQuery(t *testing.T) {
headers: nil,
},
"when header is malformed": {
statusCode: 500,
statusCode: 400,
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`),
expectErrorCode: "QueueDeletedRecently",
headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently-Sender"},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions private/protocol/jsonrpc/unmarshal_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

const (
awsQueryError = "x-amzn-query-error"
// A valid header example - "x-amzn-query-error": "<QueryErrorCode>;<ErrorType>"
awsQueryErrorPartsCount = 2
)

// UnmarshalTypedError provides unmarshaling errors API response errors
Expand Down Expand Up @@ -73,11 +75,14 @@ func (u *UnmarshalTypedError) UnmarshalError(
queryCodeParts := queryCodeParts(resp, u)

if fn, ok := u.exceptions[code]; ok {
// If exception code is know, use associated constructor to get a value
// If query-compatible exceptions are found and query-error-header is found,
// then use associated constructor to get exception with query error code.
//
// If exception code is known, use associated constructor to get a value
// for the exception that the JSON body can be unmarshaled into.
var v error
queryErrFn, queryExceptionsFound := u.queryExceptions[code]
if queryCodeParts != nil && len(queryCodeParts) == 2 && queryExceptionsFound {
if len(queryCodeParts) == awsQueryErrorPartsCount && queryExceptionsFound {
v = queryErrFn(respMeta, queryCodeParts[0])
} else {
v = fn(respMeta)
Expand All @@ -89,7 +94,7 @@ func (u *UnmarshalTypedError) UnmarshalError(
return v, nil
}

if queryCodeParts != nil && len(queryCodeParts) == 2 {
if len(queryCodeParts) == awsQueryErrorPartsCount && len(u.queryExceptions) > 0 {
code = queryCodeParts[0]
}

Expand All @@ -101,6 +106,7 @@ func (u *UnmarshalTypedError) UnmarshalError(
), nil
}

// A valid header example - "x-amzn-query-error": "<QueryErrorCode>;<ErrorType>"
func queryCodeParts(resp *http.Response, u *UnmarshalTypedError) []string {
queryCodeHeader := resp.Header.Get(awsQueryError)
var queryCodeParts []string
Expand Down

0 comments on commit 9adcdc0

Please sign in to comment.