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