diff options
Diffstat (limited to 'js/assets.js')
-rw-r--r-- | js/assets.js | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/js/assets.js b/js/assets.js index 6a2d6e2..7a04a32 100644 --- a/js/assets.js +++ b/js/assets.js @@ -483,8 +483,17 @@ callback(details); }; - let tryLoad = function () { + let tryLoad = function (tries) { let urls = []; + + let tr = (tries === undefined) ? 10 : tries; + + if (tr <= 0) { + console.warn('ηMatrix could not load the asset ' + +assetDetails.title); + return; + } + if (typeof assetDetails.contentURL === 'string') { urls = [assetDetails.contentURL]; } else if (Array.isArray(assetDetails.contentURL)) { @@ -502,10 +511,11 @@ return; } - api.fetchText(contentUrl, onRemoteContentLoad, onRemoteContentError); + api.fetchText(contentUrl, onRemoteContentLoad, onRemoteContentError, + tr-1); }; - let onRemoteContentLoad = function (details) { + let onRemoteContentLoad = function (details, tries) { if (isEmptyString(details.content) === true) { registerSource(key, { error: { @@ -513,7 +523,7 @@ error: 'No content' } }); - tryLoad(); + tryLoad(tries); } writeCache(key, { @@ -525,7 +535,7 @@ report(details.content); }; - let onRemoteContentError = function (details) { + let onRemoteContentError = function (details, tries) { let text = detail.statusText; if (details.statusCode === 0) { text = 'network error'; @@ -536,7 +546,7 @@ error: text, } }); - tryLoad(); + tryLoad(tries); }; let onReady = function (registry) { @@ -666,8 +676,9 @@ } }; - api.fetchText = function (url, onLoad, onError) { + api.fetchText = function (url, onLoad, onError, tries) { let iurl = externalPathRegex.test(url) ? url : vAPI.getURL(url); + let tr = (tries === undefined) ? 10 : tries; if (typeof onError !== 'function') { onError = onLoad; @@ -686,12 +697,12 @@ }; if (details.statusCode < 200 || details.statusCode >= 300) { - onError.call(null, details); + onError.call(null, details, tr); return; } if (isEmptyString(this.responseText) === true) { - onError.call(null, details); + onError.call(null, details, tr); return; } @@ -700,12 +711,12 @@ // Discard HTML as it's probably an error // (the request expects plain text as a response) if (t.startsWith('<') && t.endsWith('>')) { - onError.call(null, details); + onError.call(null, details, tr); return; } details.content = t; - onLoad.call(null, details); + onLoad.call(null, details, tr); }; let onErrorReceived = function () { @@ -717,7 +728,7 @@ onError.call(null, { url: url, content: '', - }); + }, tr); }; let req = new XMLHttpRequest(); @@ -783,9 +794,17 @@ cb(details); }; - let onContentNotLoaded = function (details) { + let onContentNotLoaded = function (details, tries) { let external; let urls = []; + + let tr = (tries === undefined) ? 10 : tries; + + if (tr <= 0) { + console.warn('ηMatrix couldn\'t download the asset ' + +assetDetails.title); + return; + } if (typeof assetDetails.contentURL === 'string') { urls = [assetDetails.contentURL]; @@ -808,12 +827,13 @@ return; } - api.fetchText(contentUrl, onContentLoaded, onContentNotLoaded); + api.fetchText(contentUrl, onContentLoaded, onContentNotLoaded, + tr-1); }; - let onContentLoaded = function (details) { + let onContentLoaded = function (details, tries) { if (isEmptyString(details.content) === true) { - onContentNotLoaded(); + onContentNotLoaded(undefined, tries); return; } |