From f6659e363ab94f84bb22552a7f570b6a5998ce48 Mon Sep 17 00:00:00 2001 From: barsa Date: Wed, 26 Nov 2025 17:03:31 +0900 Subject: [PATCH] Enhance FreebitOperationsService to improve entry cleanup and error handling - Updated logic to prevent cleanup of entries with a cancellation, ensuring proper handling of account states. - Enhanced error handling to fail fast on non-404 errors, optimizing resource usage during API requests. - Improved comments for clarity on the cleanup process and error handling behavior. --- .../freebit/services/freebit-operations.service.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts b/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts index 984f1a85..cadafd87 100644 --- a/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts +++ b/apps/bff/src/integrations/freebit/services/freebit-operations.service.ts @@ -82,7 +82,10 @@ export class FreebitOperationsService { ); // If all timestamps are stale (or entry is empty), mark for removal - if (timestamps.length === 0 || timestamps.every(t => t < staleThreshold)) { + // EXCEPT: Never clean up entries with a cancellation - cancellation blocks plan changes permanently + // until the account is actually cancelled or the cancellation is reverted externally + const hasCancellation = typeof entry.cancellation === "number"; + if (!hasCancellation && (timestamps.length === 0 || timestamps.every(t => t < staleThreshold))) { accountsToRemove.push(account); } } @@ -210,8 +213,11 @@ export class FreebitOperationsService { } catch (err: unknown) { lastError = err; if (getErrorMessage(err).includes("HTTP 404")) { - continue; // try next endpoint + continue; // try next endpoint for 404 (endpoint not found) } + // For non-404 errors (auth failures, rate limits, 500s, etc.), fail fast + // instead of wasting resources retrying fundamentally broken requests + break; } }