feat(browser-extension): max attempts fetching data, issues
This commit is contained in:
parent
e4b0cfd817
commit
d89b1c6c08
@ -202,9 +202,11 @@ function matchToPattern(match) {
|
||||
/**
|
||||
* @async
|
||||
* @description Refresh data
|
||||
* @param {number} [attempt]
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async function refreshData() {
|
||||
async function refreshData(attempt = 1) {
|
||||
if (attempt <= 3) {
|
||||
try {
|
||||
const { data } = await requestManager.fetch(`${apiUrl}/data/`);
|
||||
|
||||
@ -212,7 +214,8 @@ async function refreshData() {
|
||||
|
||||
return data;
|
||||
} catch {
|
||||
return await refreshData();
|
||||
return await refreshData(attempt + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -220,9 +223,11 @@ async function refreshData() {
|
||||
* @async
|
||||
* @description Refresh issues for the given hostname
|
||||
* @param {string} hostname
|
||||
* @param {number} [attempt]
|
||||
* @returns {Promise<ExtensionIssue | undefined>}
|
||||
*/
|
||||
async function refreshIssue(hostname) {
|
||||
async function refreshIssue(hostname, attempt = 1) {
|
||||
if (attempt <= 3) {
|
||||
try {
|
||||
const { data } = await requestManager.fetch(`${apiUrl}/issues/${hostname}/`);
|
||||
|
||||
@ -232,13 +237,18 @@ async function refreshIssue(hostname) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const issue = { expiresIn: Date.now() + 4 * 60 * 60 * 1000, flags: data.flags, url: data.url };
|
||||
const issue = {
|
||||
expiresIn: Date.now() + 4 * 60 * 60 * 1000,
|
||||
flags: data.flags,
|
||||
url: data.url,
|
||||
};
|
||||
|
||||
await updateStore(hostname, { issue });
|
||||
|
||||
return data;
|
||||
} catch {
|
||||
return await refreshData();
|
||||
return await refreshIssue(hostname, attempt + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user