diff --git a/extension/services/amazon.js b/extension/services/amazon.js index 778cb4b..c1b8b93 100644 --- a/extension/services/amazon.js +++ b/extension/services/amazon.js @@ -3,18 +3,30 @@ define(function (require, exports, module){ _ = require('../vendor/lodash.min'); exports.getRegistry = function(){ + function getRegistry(registryPathTemplate, defer, iteration){ + $.ajax({ + url: _.template(registryPathTemplate, { + date: new Date().getTime() + }) + }).success(function(data){ + defer.resolve(data); + }).error(function(jqXHR, status, error){ + console.error(error); + + if (iteration > 10){ + defer.reject(); + } else { + setTimeout(function(){ + getRegistry(registryPathTemplate, defer, iteration ++); + }, 1000 * (iteration + 1)); + } + }); + } + var defer = q.defer(), registryPathTemplate = 'https://s3.amazonaws.com/extend.brackets/registry.json?_=${date}'; - $.ajax({ - url: _.template(registryPathTemplate, { - date: new Date().getTime() - }) - }).success(function(data){ - defer.resolve(data); - }).error(function(){ - defer.reject(); - }); + getRegistry(registryPathTemplate, defer, 0); return defer.promise; }