Skip to content

Commit

Permalink
AWSQuery compatible error code (#4221)
Browse files Browse the repository at this point in the history
* Add awsQueryCompatible trait support to service

When awsQueryCompatible trait is found, it's made available as an API property. When this property is found,
the error code is returned by looking up the mapping. This is a pre-requisite for migrating services from
AWSQuery wire protocol to AWSJson.

* Minor edit

* Add additional tests; review comments

* Minor edits

* Sqs aws json (#2)

* Add awsQueryCompatible trait support to service

When awsQueryCompatible trait is found, it's made available as an API property. When this property is found,
the error code is returned by looking up the mapping. This is a pre-requisite for migrating services from
AWSQuery wire protocol to AWSJson.

* Minor edit

* Add additional tests; review comments

* Minor edits

* Review comments

* Use MockServiceFromApi; Move errorCodeMapping logic to even)listeners

* Update on.error function

* Fix type

* Remove reimplementation of mapping function

* Use add instead of addAsync

Co-authored-by: AllanZhengYP <zheallan@amazon.com>

* Fix lint errors

* Add null check to error listener

* Use simple service null check

* Fix add 'Error' implementation

* Add changelog

* Revert "Sqs AwsJson migration (#4105)"

This reverts commit 2a87ec1.

* Add AWSQuery error code compatibility to service

When  header value is found, then error code is populated from the header
If there is no header found, then the default error code is returned.

Co-authored-by: AllanZhengYP <zheallan@amazon.com>
  • Loading branch information
eddy-aws and AllanZhengYP authored Sep 28, 2022
1 parent d525e91 commit 8dd2749
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "feature",
"category": "AwsQueryCompatible",
"description": "Return AWSQuery compatible error code from HTTP header if found"
}
10 changes: 4 additions & 6 deletions lib/event_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,10 @@ AWS.EventListeners = {
});

add('ERROR', 'error', function ERROR(err, resp) {
var errorCodeMapping = resp.request.service.api.errorCodeMapping;
if (errorCodeMapping && err && err.code) {
var mapping = errorCodeMapping[err.code];
if (mapping) {
resp.error.code = mapping.code;
}
var headers = resp.httpResponse.headers;
var queryErrorCode = headers ? headers['x-amzn-query-error'] : undefined;
if (queryErrorCode) {
resp.error.code = queryErrorCode.split(';')[0];
}
}, true);

Expand Down
1 change: 0 additions & 1 deletion lib/model/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function Api(api, options) {
property(this, 'documentation', api.documentation);
property(this, 'documentationUrl', api.documentationUrl);
}
property(this, 'errorCodeMapping', api.awsQueryCompatible);
}

/**
Expand Down
18 changes: 11 additions & 7 deletions test/helpers.js

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

55 changes: 15 additions & 40 deletions test/service.spec.js

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

0 comments on commit 8dd2749

Please sign in to comment.