Skip to content

Commit b3820d1

Browse files
authored
Fix error code parsing in aws query compatible json services (#2852)
1 parent 1a5e99c commit b3820d1

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Fix error code parsing in AWS query compatible JSON services.
5+
46
3.171.0 (2023-03-22)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/json/error_handler.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ def extract_error(body, context)
2626
end
2727

2828
def error_code(json, context)
29-
code = if aws_query_error?(context)
30-
context.http_response.headers['x-amzn-query-error'].split(';')[0]
31-
else
32-
json['__type']
33-
end
29+
code =
30+
if aws_query_error?(context)
31+
error = context.http_response.headers['x-amzn-query-error'].split(';')[0]
32+
remove_prefix(error, context)
33+
else
34+
json['__type']
35+
end
3436
code ||= json['code']
3537
code ||= context.http_response.headers['x-amzn-errortype']
3638
if code
@@ -45,6 +47,14 @@ def aws_query_error?(context)
4547
context.http_response.headers['x-amzn-query-error']
4648
end
4749

50+
def remove_prefix(error_code, context)
51+
if prefix = context.config.api.metadata['errorPrefix']
52+
error_code.sub(/^#{prefix}/, '')
53+
else
54+
error_code
55+
end
56+
end
57+
4858
def error_message(code, json)
4959
if code == 'RequestEntityTooLarge'
5060
'Request body must be less than 1 MB'

gems/aws-sdk-core/spec/aws/json/error_handler_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ module Json
106106
'awsQueryCompatible' => {},
107107
'protocol' => 'json',
108108
'endpointPrefix' => 'svc',
109-
'signatureVersion' => 'v4'
109+
'signatureVersion' => 'v4',
110+
'errorPrefix' => 'Prefix' # service customization needs to set this
110111
},
111112
'operations' => {
112113
'Foo' => {
@@ -136,7 +137,7 @@ module Json
136137
it 'extracts code and message from x-amzn-query-error' do
137138
stub_request(:post, "https://svc.us-west-2.amazonaws.com/").
138139
to_return(:status => 400, headers: {
139-
'x-amzn-query-error': 'AwsQueryError;Sender'
140+
'x-amzn-query-error': 'Prefix.AwsQueryError;Sender'
140141
}, :body => error_resp)
141142
expect {
142143
client_aws_query_compatible.foo()

gems/aws-sdk-sqs/features/client.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Feature: Amazon Simple Queue Service
1717
Then I expect the response error code to be "NonExistentQueue"
1818
And I expect the response error message to include:
1919
"""
20-
The specified queue does not exist for this wsdl version.
20+
The specified queue does not exist.
2121
"""

0 commit comments

Comments
 (0)