From cea9422bebfcade7dc78bce8265e3ce2de80d8e9 Mon Sep 17 00:00:00 2001 From: "Ezhilan (Eddy) Ilangovan" <44303762+eddy-aws@users.noreply.github.com> Date: Mon, 24 Oct 2022 19:25:59 -0700 Subject: [PATCH] Read awsQueryCompatible trait from metadata with tests (#4254) * Read awsQueryCompatible trait from metadata with tests * Fix linting --- .../bugfix-AWSQueryCompatible-f891b653.json | 5 +++++ lib/model/api.js | 2 +- test/service.spec.js | 21 ++++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 .changes/next-release/bugfix-AWSQueryCompatible-f891b653.json diff --git a/.changes/next-release/bugfix-AWSQueryCompatible-f891b653.json b/.changes/next-release/bugfix-AWSQueryCompatible-f891b653.json new file mode 100644 index 0000000000..1059ec4d6b --- /dev/null +++ b/.changes/next-release/bugfix-AWSQueryCompatible-f891b653.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "AWSQueryCompatible", + "description": "Read trait from metadata" +} \ No newline at end of file diff --git a/lib/model/api.js b/lib/model/api.js index f59f1a6ff7..542d1d2c0f 100644 --- a/lib/model/api.js +++ b/lib/model/api.js @@ -80,7 +80,7 @@ function Api(api, options) { property(this, 'documentation', api.documentation); property(this, 'documentationUrl', api.documentationUrl); } - property(this, 'awsQueryCompatible', api.awsQueryCompatible); + property(this, 'awsQueryCompatible', api.metadata.awsQueryCompatible); } /** diff --git a/test/service.spec.js b/test/service.spec.js index 3c5cb43c13..a3a5fd4b35 100644 --- a/test/service.spec.js +++ b/test/service.spec.js @@ -15,9 +15,15 @@ describe('AWSQuery compatible error codes', function () { let service; let AwsQueryService; + let metadata = { + endpointPrefix : 'mockservice', + signatureVersion : 'v4' + }; beforeEach(function(done) { - AwsQueryService = MockServiceFromApi({awsQueryCompatible: {}}); + AwsQueryService = MockServiceFromApi({ + metadata: {...metadata, awsQueryCompatible: {}} + }); service = new AwsQueryService({maxRetries: 0}); return done(); }); @@ -26,6 +32,19 @@ return expect(service.api.awsQueryCompatible).to.eql({}); }); + it('can receive default error code when trait is not present', function() { + AwsQueryService = MockServiceFromApi({ metadata: metadata }); + service = new AwsQueryService({maxRetries: 0}); + helpers.mockHttpResponse(500, { + 'x-amzn-query-error': 'AwsQueryError;Sender' + }, ['ServiceError']); + return (service.makeRequest('operation', {}, function (err, data) { + expect(err.code).to.equal('ServiceError'); + expect(err.statusCode).to.equal(500); + return expect(data).to.equal(null); + })); + }); + it('can receive awsquery compatible error code when header present', function () { helpers.mockHttpResponse(500, { 'x-amzn-query-error': 'AwsQueryError;Sender'