Handle network error when fetching latest block

This commit is contained in:
Nabarun 2025-11-13 13:35:53 +05:30
parent 86609631c9
commit 2126c17f0d

View File

@ -191,6 +191,7 @@ export class EventWatcher {
if (isComplete) { if (isComplete) {
while (true) { while (true) {
try {
const { block: latestBlock } = await this._ethClient.getBlockByHash(); const { block: latestBlock } = await this._ethClient.getBlockByHash();
// Process block if it is blockProcessingOffset blocks behind latest block // Process block if it is blockProcessingOffset blocks behind latest block
@ -199,12 +200,18 @@ export class EventWatcher {
break; break;
} }
log(`Latest block: ${latestBlock.number}; retry next block to process: ${blockNumber + 1} after ${this._config.jobQueue.blockDelayInMilliSecs}ms`); log(`Latest block number fetched: ${latestBlock.number}`);
} catch (err: unknown) {
log(`Error while triggering processing for next block: ${blockNumber + 1}`);
log(err);
} finally {
log(`Retry next block to process: ${blockNumber + 1} after ${this._config.jobQueue.blockDelayInMilliSecs}ms`);
await wait(this._config.jobQueue.blockDelayInMilliSecs); await wait(this._config.jobQueue.blockDelayInMilliSecs);
} }
} }
} }
} }
}
handleShutdown (): void { handleShutdown (): void {
process.on('SIGINT', this._processShutdown.bind(this)); process.on('SIGINT', this._processShutdown.bind(this));