analytics-react-native
Version:
A React Native client for [Segment](https://segment.com) — The hassle-free way to integrate analytics into any application.
30 lines (25 loc) • 746 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = fetchRetry;
function fetchRetry(url) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return new Promise(function (resolve, reject) {
var _options$retries = options.retries,
retries = _options$retries === undefined ? 3 : _options$retries;
var wrappedFetch = function wrappedFetch() {
fetch(url, options).then(resolve).catch(function (error) {
if (!retries) {
reject(error);
} else {
setTimeout(function () {
retries -= 1;
wrappedFetch();
}, 1000);
}
});
};
wrappedFetch(retries);
});
}