Skip to content

Instantly share code, notes, and snippets.

@uladkasach
Created October 6, 2020 22:08
Show Gist options
  • Save uladkasach/6f3e9a8b608011ad6c8bf8a73a7f252f to your computer and use it in GitHub Desktop.
Save uladkasach/6f3e9a8b608011ad6c8bf8a73a7f252f to your computer and use it in GitHub Desktop.
/**
* 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