Last active
August 30, 2015 17:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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