Created
October 6, 2020 22:08
-
-
Save uladkasach/6f3e9a8b608011ad6c8bf8a73a7f252f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* function which calls the wrapped function and runs it again one time if an error is caught | |
*/ | |
export const withRetry = <R extends ReturnType<T>, T extends () => any>(logic: T) => { | |
return async (): Promise<R> => { | |
try { | |
return await logic(); | |
} catch (error) { | |
return await logic(); | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment