-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
dynamodb.js
58 lines (52 loc) · 1.59 KB
/
dynamodb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var AWS = require('../core');
require('../dynamodb/document_client');
AWS.util.update(AWS.DynamoDB.prototype, {
/**
* @api private
*/
setupRequestListeners: function setupRequestListeners(request) {
if (request.service.config.dynamoDbCrc32) {
request.removeListener('extractData', AWS.EventListeners.Json.EXTRACT_DATA);
request.addListener('extractData', this.checkCrc32);
request.addListener('extractData', AWS.EventListeners.Json.EXTRACT_DATA);
}
},
/**
* @api private
*/
checkCrc32: function checkCrc32(resp) {
if (!resp.httpResponse.streaming && !resp.request.service.crc32IsValid(resp)) {
resp.data = null;
resp.error = AWS.util.error(new Error(), {
code: 'CRC32CheckFailed',
message: 'CRC32 integrity check failed',
retryable: true
});
resp.request.haltHandlersOnError();
throw (resp.error);
}
},
/**
* @api private
*/
crc32IsValid: function crc32IsValid(resp) {
var crc = resp.httpResponse.headers['x-amz-crc32'];
if (!crc) return true; // no (valid) CRC32 header
return parseInt(crc, 10) === AWS.util.crypto.crc32(resp.httpResponse.body);
},
/**
* @api private
*/
defaultRetryCount: 10,
/**
* @api private
*/
retryDelays: function retryDelays(retryCount) {
var retryDelayOptions = AWS.util.copy(this.config.retryDelayOptions);
if (typeof retryDelayOptions.base !== 'number') {
retryDelayOptions.base = 50; // default for dynamodb
}
var delay = AWS.util.calculateRetryDelay(retryCount, retryDelayOptions);
return delay;
}
});