From c93474d3d5109e0624cfbdd70d60e5a9009e6906 Mon Sep 17 00:00:00 2001 From: Simon Grim Date: Thu, 5 May 2016 09:14:35 +0500 Subject: [PATCH] retry to decode shortened URI if we got null response --- js/interface_common.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index 04dc8f7..39111f5 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -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} ); }