Skip to content

Instantly share code, notes, and snippets.

@AzimUddin
Last active August 30, 2015 17:52
Show Gist options
  • Save AzimUddin/b647519d633477be313f to your computer and use it in GitHub Desktop.
Save AzimUddin/b647519d633477be313f to your computer and use it in GitHub Desktop.
Azure DocumentDB node.js example of executing a method with retry to handle RequestRateTooLargeException or HTTP 429 errors
var queryIterator = documentClient.queryDocuments(collection._self, query);
executeNextWithRetry(yourCallback);
function executeNextWithRetry(callback) {
queryIterator.executeNext(function(err, results, responseHeaders) {
if(err && err.code === 429 && responseHeaders['x-ms-retry-after-ms']) {
console.log("Retrying after " + responseHeaders['x-ms-retry-after-ms']);
setTimeout(function() {
executeNextWithRetry(callback);
}, responseHeaders['x-ms-retry-after-ms']);
} else {
callback(err, results, responseHeaders);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment