diff options
Diffstat (limited to 'content')
-rw-r--r-- | content/repo_query_cacher.js | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/content/repo_query_cacher.js b/content/repo_query_cacher.js index 3f62be7..be97c39 100644 --- a/content/repo_query_cacher.js +++ b/content/repo_query_cacher.js @@ -43,10 +43,12 @@ */ #FROM common/browser.js IMPORT browser +#FROM common/misc.js IMPORT error_data_jsonifiable /* * Map URLs to objects containing parsed responses, error info or promises - * resolving to those. + * resolving to those. The use of promises helps us prevent multiple requests + * for the same resource from starting concurrently. */ const cache = new Map(); @@ -58,12 +60,11 @@ async function perform_download(url) { cache.set(url, new Promise(cb => resolve_cb = cb)); try { - const opts = {url, to_get: ["ok", "status"], to_call: ["json"]}; - var result = await browser.runtime.sendMessage(["CORS_bypass", opts]); + var result = await browser.runtime.sendMessage(["CORS_bypass", {url}]); if (result === undefined) - result = {error: "Couldn't communicate with background script."}; + throw new Error("Couldn't communicate with background script."); } catch(e) { - var result = {error: e + ""}; + return {error: error_data_jsonifiable(e)}; } cache.set(url, result); |