Report a rate-limited bank sync as a wait, and name real failures
Two of three banks were only pacing us, yet the dashboard demanded attention, printed four nested wrappers and a nanosecond UTC deadline, and the scheduler retried hourly into a refusal whose end time the bank had already given. A rate limit now carries its retry time as data: Status.SyncRetryAt is set when every failure is self-clearing, the connection reports rate_limited with that deadline, the dashboard says synchronization resumes by itself and renders the time in the browser's zone, and the scheduler sleeps until the deadline instead of spending hourly session checks. Sync now still tries immediately. The third bank's "transaction retrieval failed" hid its cause. Provider failures Finance Duck determines itself are typed as banking.ProviderError, so an unreachable provider, a timeout or an unusable response, such as a booked transaction without a booking date, is reported instead of the opaque fallback. Provider response text still never reaches the message.
This commit is contained in:
+29
-1
@@ -70,9 +70,16 @@ export interface Connection {
|
||||
country: string;
|
||||
psu_type: string;
|
||||
history_months: number;
|
||||
status: "local" | "connected" | "reconnect_required" | "error";
|
||||
status:
|
||||
| "local"
|
||||
| "connected"
|
||||
| "reconnect_required"
|
||||
| "rate_limited"
|
||||
| "error";
|
||||
valid_until: string;
|
||||
error: string;
|
||||
// retry_at is set while the bank rate limits this connection.
|
||||
retry_at?: string;
|
||||
}
|
||||
export interface Institution {
|
||||
name: string;
|
||||
@@ -88,6 +95,9 @@ export interface State {
|
||||
connections: Connection[];
|
||||
status: {
|
||||
sync_error: string;
|
||||
// sync_retry_at is set only when every failure is a bank rate limit that
|
||||
// clears by itself.
|
||||
sync_retry_at?: string;
|
||||
index_error: string;
|
||||
last_sync: string;
|
||||
banking_configured: boolean;
|
||||
@@ -252,6 +262,24 @@ export function normalizeState(state: State): State {
|
||||
for (const session of state.sessions) session.accounts ??= [];
|
||||
return state;
|
||||
}
|
||||
// Retry deadlines are instants, not calendar days: show them in the viewer's
|
||||
// own time zone rather than the server's UTC string.
|
||||
export function localInstant(iso: string): string {
|
||||
const at = new Date(iso);
|
||||
if (!iso || Number.isNaN(at.getTime())) return iso;
|
||||
const sameDay = at.toDateString() === new Date().toDateString();
|
||||
return at.toLocaleString(
|
||||
undefined,
|
||||
sameDay
|
||||
? { hour: "2-digit", minute: "2-digit" }
|
||||
: {
|
||||
day: "2-digit",
|
||||
month: "short",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
},
|
||||
);
|
||||
}
|
||||
export function money(value: string, currency: string): string {
|
||||
// Keep all financial values as decimal strings, including display formatting.
|
||||
const match = /^(-?)(\d+)(?:\.(\d+))?$/.exec(value);
|
||||
|
||||
Reference in New Issue
Block a user