@faast/tron-payments
Version:
Library to assist in processing tron payments, such as deriving addresses and sweeping funds
27 lines • 791 B
JavaScript
import { isMatchingError } from '@faast/ts-common';
import promiseRetry from 'promise-retry';
export function toError(e) {
if (typeof e === 'string') {
return new Error(e);
}
return e;
}
const RETRYABLE_ERRORS = [
'Request failed',
];
const MAX_RETRIES = 2;
export function retryIfDisconnected(fn, logger) {
return promiseRetry((retry, attempt) => {
return fn().catch(async (e) => {
e = toError(e);
if (isMatchingError(e, RETRYABLE_ERRORS)) {
logger.log(`Retryable error during tron-payments call, retrying ${MAX_RETRIES - attempt} more times`, e.toString());
retry(e);
}
throw e;
});
}, {
retries: MAX_RETRIES,
});
}
//# sourceMappingURL=utils.js.map