shopify-api-node
Advanced tools
Comparing version 3.11.1 to 3.11.2
95
index.js
@@ -22,6 +22,7 @@ 'use strict'; | ||
]); | ||
const retryableErrorCodesArray = Array.from(retryableErrorCodes); | ||
const retryableStatusCodes = new Set([ | ||
const retryableStatusCodesArray = [ | ||
408, 413, 429, 500, 502, 503, 504, 521, 522, 524 | ||
]); | ||
]; | ||
@@ -160,6 +161,9 @@ /** | ||
? { | ||
calculateDelay, | ||
errorCodes: retryableErrorCodesArray, | ||
limit: this.options.maxRetries, | ||
// Don't clamp Shopify `Retry-After` header values too low. | ||
maxRetryAfter: Infinity, | ||
calculateDelay | ||
methods: [method], | ||
statusCodes: retryableStatusCodesArray | ||
} | ||
@@ -277,6 +281,9 @@ : 0, | ||
? { | ||
calculateDelay, | ||
errorCodes: retryableErrorCodesArray, | ||
limit: this.options.maxRetries, | ||
// Don't clamp Shopify `Retry-After` header values too low. | ||
maxRetryAfter: Infinity, | ||
calculateDelay | ||
methods: ['POST'], | ||
statusCodes: retryableStatusCodesArray | ||
} | ||
@@ -311,14 +318,2 @@ : 0, | ||
/** | ||
* Got `calculateDelay` hook function passed to decide how long to wait before | ||
* retrying. | ||
* | ||
* @param {Object} retryObject Got's input for the retry logic | ||
* @return {Number} The delay | ||
* @private | ||
*/ | ||
function calculateDelay(retryObject) { | ||
return maybeRetryMS(retryObject.error) || retryObject.computedValue; | ||
} | ||
/** | ||
* Decorates an `Error` object with details from GraphQL errors in the response | ||
@@ -358,45 +353,49 @@ * body. | ||
* | ||
* @param {Object} error Error object from Got call | ||
* @return {(Number|null)} The duration in ms, or `null` | ||
* @param {Object} retryObject Got's input for the retry logic | ||
* @return {Number} The duration in ms | ||
* @private | ||
**/ | ||
function maybeRetryMS(error) { | ||
// For simplicity, retry network connectivity issues after a hardcoded 1s. | ||
if (retryableErrorCodes.has(error.code)) { | ||
return 1000; | ||
} | ||
function calculateDelay(retryObject) { | ||
const { error, computedValue } = retryObject; | ||
const response = error.response; | ||
if (response.headers && response.headers['retry-after']) { | ||
return response.headers['retry-after'] * 1000 || null; | ||
// Detect GraphQL request throttling. | ||
if ( | ||
response && | ||
response.statusCode === 200 && | ||
response.body && | ||
typeof response.body === 'object' && | ||
Array.isArray(response.body.errors) && | ||
response.body.errors[0].extensions && | ||
response.body.errors[0].extensions.code == 'THROTTLED' | ||
) { | ||
const costData = response.body.extensions.cost; | ||
return ( | ||
((costData.requestedQueryCost - | ||
costData.throttleStatus.currentlyAvailable) / | ||
costData.throttleStatus.restoreRate) * | ||
1000 | ||
); | ||
} | ||
if (retryableStatusCodes.has(response.statusCode)) { | ||
// Arbitrary 2 seconds, in case we get a 429 without a `Retry-After` | ||
// response header, or 4xx/5xx series error that matches the Got retry | ||
// defaults. | ||
return 2 * 1000; | ||
// Stop retrying if the attempt limit has been reached or the request is not | ||
// retryable. | ||
if (computedValue === 0) { | ||
return 0; | ||
} | ||
// Detect GraphQL request throttling. | ||
if (response.body && typeof response.body === 'object') { | ||
const body = response.body; | ||
// For simplicity, retry network connectivity issues after a hardcoded 1s. | ||
if (retryableErrorCodes.has(error.code)) { | ||
return 1000; | ||
} | ||
if ( | ||
Array.isArray(body.errors) && | ||
body.errors[0].extensions && | ||
body.errors[0].extensions.code == 'THROTTLED' | ||
) { | ||
const costData = body.extensions.cost; | ||
return ( | ||
((costData.requestedQueryCost - | ||
costData.throttleStatus.currentlyAvailable) / | ||
costData.throttleStatus.restoreRate) * | ||
1000 | ||
); | ||
} | ||
if (response.headers && response.headers['retry-after']) { | ||
return response.headers['retry-after'] * 1000 || computedValue; | ||
} | ||
return null; | ||
// Arbitrary 2 seconds, in case we get a 429 without a `Retry-After` | ||
// response header, or 4xx/5xx series error that matches the Got retry | ||
// defaults. | ||
return 2 * 1000; | ||
} | ||
@@ -403,0 +402,0 @@ |
{ | ||
"name": "shopify-api-node", | ||
"version": "3.11.1", | ||
"version": "3.11.2", | ||
"description": "Shopify API bindings for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
210155