From 2f1f970267fd9f28edace55d453c9d8f45eb69b6 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 9 Jun 2025 23:38:35 +0200 Subject: [PATCH] updates --- docs/email-system-fixes.md | 6 ++++-- server/utils/nocodb.ts | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/email-system-fixes.md b/docs/email-system-fixes.md index 66c9c6e..ec61776 100644 --- a/docs/email-system-fixes.md +++ b/docs/email-system-fixes.md @@ -84,9 +84,11 @@ ### 11. 404 Errors for Newly Created Records - **Problem**: Newly created records sometimes show 404 when immediately updating/linking - **Solution**: - - Added better error logging to identify when this happens + - Added retry mechanism with exponential backoff to `updateInterest` function + - Will retry up to 3 times with increasing delays (1s, 2s, 3s) - `get-interest-berths` returns empty list instead of throwing error for new records - - This appears to be a sync delay in NocoDB - record needs a moment to propagate + - This handles NocoDB synchronization delays where records need time to propagate + - After 3 retries, provides detailed error message explaining possible causes ## Required Environment Variables diff --git a/server/utils/nocodb.ts b/server/utils/nocodb.ts index 62645ea..5537ead 100644 --- a/server/utils/nocodb.ts +++ b/server/utils/nocodb.ts @@ -37,8 +37,8 @@ export const getInterestById = async (id: string) => }, }); -export const updateInterest = async (id: string, data: Partial) => { - console.log('[nocodb.updateInterest] Updating interest:', id); +export const updateInterest = async (id: string, data: Partial, retryCount = 0): Promise => { + console.log('[nocodb.updateInterest] Updating interest:', id, 'Retry:', retryCount); console.log('[nocodb.updateInterest] Data fields:', Object.keys(data)); // Create a clean data object that matches the InterestsRequest schema @@ -110,12 +110,24 @@ export const updateInterest = async (id: string, data: Partial) => { console.error('[nocodb.updateInterest] Update failed:', error); console.error('[nocodb.updateInterest] Error details:', error instanceof Error ? error.message : 'Unknown error'); - // If it's a 404 error for a newly created record, provide more context + // If it's a 404 error and we haven't retried too many times, wait and retry + if ((error.statusCode === 404 || error.status === 404) && retryCount < 3) { + console.error('[nocodb.updateInterest] 404 Error - Record not found. This might be a sync delay.'); + console.error(`Retrying in ${(retryCount + 1) * 1000}ms... (Attempt ${retryCount + 1}/3)`); + + // Wait with exponential backoff + await new Promise(resolve => setTimeout(resolve, (retryCount + 1) * 1000)); + + // Retry the update + return updateInterest(id, data, retryCount + 1); + } + + // If it's still a 404 after retries, provide detailed error if (error.statusCode === 404 || error.status === 404) { - console.error('[nocodb.updateInterest] 404 Error - Record not found. This might happen if:'); + console.error('[nocodb.updateInterest] 404 Error - Record not found after 3 retries. This might happen if:'); console.error('1. The record ID is incorrect'); - console.error('2. The record was just created and is not yet available'); - console.error('3. The record was deleted'); + console.error('2. The record was deleted'); + console.error('3. There is a synchronization issue with the database'); console.error('Attempted URL:', url); }