From 18821fd560675556f6d6dc4a959f4c475a1d5502 Mon Sep 17 00:00:00 2001 From: fahed Date: Thu, 26 Mar 2026 16:59:21 +0300 Subject: [PATCH] fix: fetch ERP months sequentially to avoid 500 errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ERP API can't handle concurrent requests — switch from batched parallel (4 at a time) to sequential fetching. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/services/erpService.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/services/erpService.ts b/src/services/erpService.ts index e66d160..fcb4a02 100644 --- a/src/services/erpService.ts +++ b/src/services/erpService.ts @@ -85,18 +85,12 @@ export async function fetchFromERP(): Promise { console.log('Fetching from ERP API via proxy...'); const months = generateMonthBoundaries(2024, 1); - // Fetch all months in parallel (batched in groups of 4 to avoid overwhelming) - const batchSize = 4; + // Fetch months sequentially — the ERP API doesn't handle concurrent requests well const allSales: ERPSaleRecord[] = []; - for (let i = 0; i < months.length; i += batchSize) { - const batch = months.slice(i, i + batchSize); - const results = await Promise.all( - batch.map(([start, end]) => fetchChunk(start, end)) - ); - for (const chunk of results) { - allSales.push(...chunk); - } + for (const [start, end] of months) { + const chunk = await fetchChunk(start, end); + allSales.push(...chunk); } console.log(`Fetched ${allSales.length} transactions, aggregating...`);