@@ -15,6 +15,8 @@ import (
15
15
16
16
const (
17
17
awsQueryError = "x-amzn-query-error"
18
+ // A valid header example - "x-amzn-query-error": "<QueryErrorCode>;<ErrorType>"
19
+ awsQueryErrorPartsCount = 2
18
20
)
19
21
20
22
// UnmarshalTypedError provides unmarshaling errors API response errors
@@ -73,11 +75,14 @@ func (u *UnmarshalTypedError) UnmarshalError(
73
75
queryCodeParts := queryCodeParts (resp , u )
74
76
75
77
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
77
82
// for the exception that the JSON body can be unmarshaled into.
78
83
var v error
79
84
queryErrFn , queryExceptionsFound := u .queryExceptions [code ]
80
- if queryCodeParts != nil && len (queryCodeParts ) == 2 && queryExceptionsFound {
85
+ if len (queryCodeParts ) == awsQueryErrorPartsCount && queryExceptionsFound {
81
86
v = queryErrFn (respMeta , queryCodeParts [0 ])
82
87
} else {
83
88
v = fn (respMeta )
@@ -89,7 +94,7 @@ func (u *UnmarshalTypedError) UnmarshalError(
89
94
return v , nil
90
95
}
91
96
92
- if queryCodeParts != nil && len (queryCodeParts ) == 2 {
97
+ if len ( queryCodeParts ) == awsQueryErrorPartsCount && len (u . queryExceptions ) > 0 {
93
98
code = queryCodeParts [0 ]
94
99
}
95
100
@@ -101,6 +106,7 @@ func (u *UnmarshalTypedError) UnmarshalError(
101
106
), nil
102
107
}
103
108
109
+ // A valid header example - "x-amzn-query-error": "<QueryErrorCode>;<ErrorType>"
104
110
func queryCodeParts (resp * http.Response , u * UnmarshalTypedError ) []string {
105
111
queryCodeHeader := resp .Header .Get (awsQueryError )
106
112
var queryCodeParts []string
0 commit comments