Skip to content

Commit 3cc5536

Browse files
committed
Add support for request ID in all services.
This is a breaking change that renames the `response.data.RequestId` property to `response.requestId`. To migrate your code, change: svc.operation(params, function (err, data) { console.log('Request ID:', data.RequestId); }); To the following: svc.operation(params, function () { console.log('Request ID:', this.requestId); }); Closes #215
1 parent a933607 commit 3cc5536

File tree

6 files changed

+17
-32
lines changed

6 files changed

+17
-32
lines changed

lib/event_listeners.js

+7
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ AWS.EventListeners = {
295295

296296
}),
297297

298+
CorePost: new AWS.SequentialExecutor().addNamedListeners(function(add) {
299+
add('EXTRACT_REQUEST_ID', 'extractData', function EXTRACT_REQUEST_ID(resp) {
300+
resp.requestId = resp.httpResponse.headers['x-amz-request-id'] ||
301+
resp.httpResponse.headers['x-amzn-requestid'];
302+
});
303+
}),
304+
298305
Logger: new AWS.SequentialExecutor().addNamedListeners(function(add) {
299306
add('LOG_REQUEST', 'complete', function LOG_REQUEST(resp) {
300307
var req = resp.request;

lib/response.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,11 @@ var inherit = AWS.util.inherit;
6161
* * retryable [Boolean] whether the error message is
6262
* retryable.
6363
*
64-
* @!attribute service
64+
* @!attribute requestId
6565
* @readonly
66-
* @!group Operation Properties
67-
* @return [AWS.Service] The service object that initiated the request.
68-
*
69-
* @!attribute operation
70-
* @readonly
71-
* @!group Operation Properties
72-
* @return [String] the name of the operation executed on
73-
* the service.
74-
*
75-
* @!attribute params
76-
* @readonly
77-
* @!group Operation Properties
78-
* @return [Object] the parameters sent in the request to
79-
* the service.
66+
* @!group Data Properties
67+
* @return [String] the unique request ID associated with the response.
68+
* Log this value when debugging requests for AWS support.
8069
*
8170
* @!attribute retryCount
8271
* @readonly

lib/service.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ AWS.Service = inherit({
199199
* @api private
200200
*/
201201
addAllRequestListeners: function addAllRequestListeners(request) {
202-
var list = [AWS.events, AWS.EventListeners.Core,
203-
this.serviceInterface()];
202+
var list = [AWS.events, AWS.EventListeners.Core, this.serviceInterface(),
203+
AWS.EventListeners.CorePost];
204204
for (var i = 0; i < list.length; i++) {
205205
if (list[i]) request.addListeners(list[i]);
206206
}

lib/service_interface/rest_json.js

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ AWS.ServiceInterface.RestJson = {
3131
AWS.ServiceInterface.Json.extractData(resp);
3232
resp.data = AWS.util.merge(data, resp.data);
3333
}
34-
35-
// extract request id
36-
resp.data.RequestId = resp.httpResponse.headers['x-amz-request-id'] ||
37-
resp.httpResponse.headers['x-amzn-requestid'];
3834
},
3935

4036
populateBody: function populateBody(req) {

lib/service_interface/rest_xml.js

-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ AWS.ServiceInterface.RestXml = {
5151
var parser = new AWS.XML.Parser(operation.output || {});
5252
AWS.util.update(resp.data, parser.parse(httpResponse.body.toString()));
5353
}
54-
55-
// extract request id
56-
resp.data.RequestId = httpResponse.headers['x-amz-request-id'] ||
57-
httpResponse.headers['x-amzn-requestid'];
5854
},
5955

6056
populateBody: function populateBody(req) {

test/services/s3.spec.coffee

+4-7
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,7 @@ describe 'AWS.S3', ->
245245
Type: 'Group',
246246
URI: 'uri'
247247
}
248-
],
249-
RequestId : 'request-id'
248+
]
250249
})
251250

252251
describe 'putBucketAcl', ->
@@ -324,8 +323,8 @@ describe 'AWS.S3', ->
324323
Bucket: 'Example-Bucket'
325324
Key: 'Example-Object'
326325
ETag: '"3858f62230ac3c915f300c664312c11f-9"'
327-
RequestId: '656c76696e6727732072657175657374'
328326
})
327+
expect(this.requestId).toEqual('656c76696e6727732072657175657374')
329328

330329
it 'returns an error when the resp is 200 with an error xml document', ->
331330
body =
@@ -363,10 +362,8 @@ describe 'AWS.S3', ->
363362
helpers.mockHttpResponse 200, headers, body
364363
s3.getBucketLocation (error, data) ->
365364
expect(error).toBe(null)
366-
expect(data).toEqual({
367-
LocationConstraint: 'EU',
368-
RequestId: 'abcxyz',
369-
})
365+
expect(data).toEqual(LocationConstraint: 'EU')
366+
expect(this.requestId).toEqual('abcxyz')
370367

371368
describe 'createBucket', ->
372369
it 'auto-populates the LocationConstraint based on the region', ->

0 commit comments

Comments
 (0)