-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #612 from newfold-labs/fix/onboarding-flow-error
Fix Onboarding Flow GET Error
- Loading branch information
Showing
4 changed files
with
35 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Retries a given API function until the specified retry count is reached. | ||
* | ||
* @param {Function} func - The API function to be retried. It should return a promise. | ||
* @param {number} retryCount - The number of times to retry the function before giving up. | ||
* @return {Promise<any|boolean>} - Resolves with the data returned by the API function if successful, or `false` if all retries fail. | ||
*/ | ||
export async function functionRetryHandler( func, retryCount ) { | ||
let attempts = 0; | ||
while ( attempts < retryCount ) { | ||
try { | ||
const data = await func(); | ||
attempts++; | ||
if ( data.error === null ) { | ||
return data; | ||
} | ||
} catch ( error ) { | ||
attempts++; | ||
// eslint-disable-next-line no-console | ||
console.error( 'Failed to retrieve data', error ); | ||
|
||
if ( attempts >= retryCount ) { | ||
return false; | ||
} | ||
} | ||
} | ||
return false; | ||
} |