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.
This commit is contained in:
barsa 2025-11-26 17:03:31 +09:00
parent e228f9342f
commit f6659e363a

View File

@ -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;
}
}