retry to decode shortened URI if we got null response

This commit is contained in:
Simon Grim 2016-05-05 09:14:35 +05:00
parent dccc5695e0
commit c93474d3d5

View File

@ -879,7 +879,7 @@ function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) {
return formatted;
}
function fetchShortenedURI(req) {
function fetchShortenedURI(req, attemptCount) {
if (twister.URIs[req]) {
applyShortenedURI(req, twister.URIs[req]);
return;
@ -888,13 +888,15 @@ function fetchShortenedURI(req) {
decodeShortURI(req,
function (req, ret) {
if (ret) {
twister.URIs[req] = ret;
twister.URIs[req.shortURI] = ret;
$.localStorage.set('twistaURIs', twister.URIs);
applyShortenedURI(req, ret);
applyShortenedURI(req.shortURI, ret);
} else {
console.warn('can\'t fetch URI "' + req + '": null response');
console.warn('can\'t fetch URI "' + req.shortURI + '": null response');
if ((req.attemptCount ? ++req.attemptCount : req.attemptCount = 1) < 3) // < $.Options.decodeShortURITriesMax
fetchShortenedURI(req.shortURI, req.attemptCount);
}
}, req
}, {short: req, attemptCount: attemptCount}
);
}