From c26fa76f5335b9d610cefca8bccea50581669e0e Mon Sep 17 00:00:00 2001 From: tophf Date: Mon, 30 Apr 2018 20:05:52 +0300 Subject: [PATCH] retry the update check on 503 fixes #380 --- background/update.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/background/update.js b/background/update.js index 07e6a6a5..18be9280 100644 --- a/background/update.js +++ b/background/update.js @@ -28,6 +28,8 @@ global API_METHODS let logQueue = []; let logLastWriteTime = 0; + const retrying = new Set(); + API_METHODS.updateCheckAll = checkAllStyles; API_METHODS.updateCheck = checkStyle; API_METHODS.getUpdaterStates = () => STATES; @@ -44,6 +46,7 @@ global API_METHODS } = {}) { resetInterval(); checkingAll = true; + retrying.clear(); const port = observe && chrome.runtime.connect({name: 'updater'}); return getStyles({}).then(styles => { styles = styles.filter(style => style.updateUrl); @@ -58,6 +61,7 @@ global API_METHODS if (port) port.disconnect(); log(''); checkingAll = false; + retrying.clear(); }); } @@ -98,6 +102,15 @@ global API_METHODS } function reportFailure(error) { + // retry once if the error is 503 Service Unavailable + if (error === 503 && !retrying.get(id)) { + retrying.add(id); + return new Promise(resolve => { + setTimeout(() => { + resolve(checkStyle(id, style, port, save, ignoreDigest)); + }, 1000); + }); + } error = error === 0 ? 'server unreachable' : error; log(STATES.SKIPPED + ` (${error}) #${style.id} ${style.name}`); const info = {error, STATES, style: getStyleWithNoCode(style)};