Retrying API with HTTP status code 202


Last updated
Was this helpful?
Was this helpful?
async function makeApiCallWithRetry(maxRetries = 10, delay = 2000) {
let retries = 0;
while (retries < maxRetries) {
const response = await {{actions.apiCall.trigger()}}
// If the response is 200, return the data
if (response.status === 200) {
return response.body;
}
// If the response is 202, retry after a delay
if (response.status === 202) {
retries++;
await new Promise(res => setTimeout(res, delay));
} else {
throw new Error(`Unexpected status code: ${response.status}`);
}
}
}
return await makeApiCallWithRetry();actions.apiCall.trigger() -> actions[params.actionName].trigger()