feat(browser-extension): max attempts fetching data, issues
This commit is contained in:
parent
e4b0cfd817
commit
d89b1c6c08
@ -202,17 +202,20 @@ 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) {
|
||||||
try {
|
if (attempt <= 3) {
|
||||||
const { data } = await requestManager.fetch(`${apiUrl}/data/`);
|
try {
|
||||||
|
const { data } = await requestManager.fetch(`${apiUrl}/data/`);
|
||||||
|
|
||||||
await updateStore('data', data);
|
await updateStore('data', data);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
} catch {
|
} catch {
|
||||||
return await refreshData();
|
return await refreshData(attempt + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,25 +223,32 @@ 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) {
|
||||||
try {
|
if (attempt <= 3) {
|
||||||
const { data } = await requestManager.fetch(`${apiUrl}/issues/${hostname}/`);
|
try {
|
||||||
|
const { data } = await requestManager.fetch(`${apiUrl}/issues/${hostname}/`);
|
||||||
|
|
||||||
if (Object.keys(data).length === 0) {
|
if (Object.keys(data).length === 0) {
|
||||||
await updateStore(hostname, { issue: { expiresIn: Date.now() + 8 * 60 * 60 * 1000 } });
|
await updateStore(hostname, { issue: { expiresIn: Date.now() + 8 * 60 * 60 * 1000 } });
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const issue = {
|
||||||
|
expiresIn: Date.now() + 4 * 60 * 60 * 1000,
|
||||||
|
flags: data.flags,
|
||||||
|
url: data.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
await updateStore(hostname, { issue });
|
||||||
|
|
||||||
|
return data;
|
||||||
|
} catch {
|
||||||
|
return await refreshIssue(hostname, attempt + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user