From 63640674ca4575ebc9a0895cb8969898ccb6890e Mon Sep 17 00:00:00 2001 From: Doron Zavelevsky Date: Sat, 14 Dec 2024 01:16:42 +0000 Subject: [PATCH] error handling in sync --- src/chain-cache/ChainSync.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/chain-cache/ChainSync.ts b/src/chain-cache/ChainSync.ts index 0f80ba2..c58fc62 100644 --- a/src/chain-cache/ChainSync.ts +++ b/src/chain-cache/ChainSync.ts @@ -152,18 +152,24 @@ export class ChainSync { ) { batches.push(this._uncachedPairs.slice(i, i + this._numOfPairsToBatch)); } - this._uncachedPairs = []; - const strategiesBatches = await Promise.all( - batches.map((batch) => this._fetcher.strategiesByPairs(batch)) - ); - strategiesBatches.flat().forEach((pairStrategies) => { - this._chainCache.addPair( - pairStrategies.pair[0], - pairStrategies.pair[1], - pairStrategies.strategies, - true + + try { + const strategiesBatches = await Promise.all( + batches.map((batch) => this._fetcher.strategiesByPairs(batch)) ); - }); + strategiesBatches.flat().forEach((pairStrategies) => { + this._chainCache.addPair( + pairStrategies.pair[0], + pairStrategies.pair[1], + pairStrategies.strategies, + true + ); + }); + this._uncachedPairs = []; + } catch (error) { + logger.error('Failed to fetch strategies for pairs batch:', error); + throw error; // Re-throw to be handled by caller + } } public async syncPairData(token0: string, token1: string): Promise {