Skip to content

Commit 9adcdc0

Browse files
committed
Review comments
1 parent ef33e60 commit 9adcdc0

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

private/model/api/codegentest/models/awsquerycompatible/api-2.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"awsQueryCompatible": {
77

88
},
9-
"endpointPrefix":"awsquerycompatible",
9+
"endpointPrefix":"awsqc-exampleendpoint",
1010
"jsonVersion":"1.1",
1111
"protocol":"json",
1212
"serviceAbbreviation":"AwsQueryCompatible",

private/model/api/codegentest/service/awsquerycompatible/awsquerycompatible_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ func TestAWSQuery(t *testing.T) {
2929
expectErrorCode string
3030
}{
3131
"when header is present": {
32-
statusCode: 500,
32+
statusCode: 400,
3333
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`),
3434
expectErrorCode: "AWS.SimpleQueueService.QueueDeletedRecently",
3535
headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently;Sender"},
3636
},
37-
"for unmodlled error code": {
37+
"for unmodeled error code": {
3838
statusCode: 400,
3939
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#AccessDeniedException", "message":"Some user-visible message"}`),
4040
expectErrorCode: "AccessDenied",
@@ -53,7 +53,7 @@ func TestAWSQuery(t *testing.T) {
5353
headers: nil,
5454
},
5555
"when header is malformed": {
56-
statusCode: 500,
56+
statusCode: 400,
5757
responseBody: strings.NewReader(`{"__type":"com.amazonaws.awsquerycompatible#QueueDeletedRecently", "message":"Some user-visible message"}`),
5858
expectErrorCode: "QueueDeletedRecently",
5959
headers: map[string]string{"x-amzn-query-error": "AWS.SimpleQueueService.QueueDeletedRecently-Sender"},

private/model/api/codegentest/service/awsquerycompatible/service.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

private/protocol/jsonrpc/unmarshal_error.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
const (
1717
awsQueryError = "x-amzn-query-error"
18+
// A valid header example - "x-amzn-query-error": "<QueryErrorCode>;<ErrorType>"
19+
awsQueryErrorPartsCount = 2
1820
)
1921

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

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

92-
if queryCodeParts != nil && len(queryCodeParts) == 2 {
97+
if len(queryCodeParts) == awsQueryErrorPartsCount && len(u.queryExceptions) > 0 {
9398
code = queryCodeParts[0]
9499
}
95100

@@ -101,6 +106,7 @@ func (u *UnmarshalTypedError) UnmarshalError(
101106
), nil
102107
}
103108

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

0 commit comments

Comments
 (0)