Skip to content

Error Handling

Handle Client and Server SDK envelopes, retries, and terminal errors safely.

Finatic SDKs return structured failures. Check the envelope for the SDK you use before reading data, and keep credentials and raw broker payloads out of user-visible errors.

Client SDK envelope

The browser Client SDK returns success, error, and warning:

1const result = await finatic.v1.listAccounts({ includeSyncStatus: true }); 2 3if (result.error) { 4 console.error(result.error.code, result.error.message, result.error.status); 5 return; 6} 7 8const accounts = result.success?.data ?? []; 9for (const warning of result.warning ?? []) { 10 console.warn(warning.message); 11} 12

Server SDK envelopes

The Node and Python Server SDKs return data, errors, warnings, and traceId:

1const result = await finatic.v1.listAccounts(); 2 3if (result.errors?.length) { 4 console.error(result.traceId, result.errors); 5 return; 6} 7 8const accounts = result.data ?? []; 9for (const warning of result.warnings ?? []) { 10 console.warn(warning); 11}

Keep traceId in tenant-safe internal logs and support reports. Never log API keys, Connect tokens, webhook secrets, or raw provider credentials.

Common first-run errors

Code or statusMeaningAction
Token 401 / expiredThe one-time Connect token lived about 90 secondsMint a new token immediately before FinaticConnect.init
SESSION_INVALID_STATEConnect is incomplete or no active grant existsComplete Connect and wait for account.grant.created
ACCOUNT_ID_TYPE_MISMATCHA tenant/company ID was used as accountIdUse the financial account ID from the grant event or listAccounts
403The current grant or API key lacks accessStop and repair authorization instead of retrying
404The resource is absent or outside the authorized accountVerify identifiers and tenant ownership
422Validation failedCorrect the request from returned field details
429The rate limit was reachedRetry only a safe read after Retry-After

Bounded retries for safe reads

Retry only idempotent reads after transport failures, 429, or transient 5xx responses. Bound attempts, honor Retry-After, add jitter, and surface the final error.

1const RETRYABLE_STATUS = new Set([429, 500, 502, 503, 504]); 2 3async function listAccountsWithRetry(maxAttempts = 3) { 4 for (let attempt = 1; attempt <= maxAttempts; attempt += 1) { 5 let result; 6 7 try { 8 result = await finatic.v1.listAccounts(); 9 } catch (transportError) { 10 if (attempt === maxAttempts) throw transportError; 11 await new Promise((resolve) => 12 setTimeout(resolve, 250 * 2 ** (attempt - 1)), 13 ); 14 continue; 15 } 16 17 if (!result.error) return result.success?.data ?? []; 18 19 const status = result.error.status; 20 if (!status || !RETRYABLE_STATUS.has(status) || attempt === maxAttempts) { 21 throw new Error(result.error.message); 22 } 23 24 const retryAfterSeconds = Number(result.error.details?.retry_after ?? 0); 25 const backoffMs = Math.max( 26 retryAfterSeconds * 1000, 27 250 * 2 ** (attempt - 1), 28 ); 29 await new Promise((resolve) => 30 setTimeout(resolve, backoffMs + Math.floor(Math.random() * 100)), 31 ); 32 } 33 34 throw new Error('Account read exhausted its retry budget'); 35} 36

Do not automatically retry order placement, modification, or cancellation with a new idempotency key. A timeout can happen after the broker accepted the command. Preserve the original key and reconcile order state before submitting another trade.

Readiness is asynchronous

account.grant.created confirms durable authorization. Initial account data may still be pending. Poll a bounded number of times or consume supported events, show a visible pending state, and finish with a timeout or error state instead of an infinite spinner.

Operational guidance

  1. Translate technical failures into safe user-facing messages.
  2. Log stable error codes, HTTP status, and traceId with tenant-safe context.
  3. Never retry 401, 403, 404, or 422 without changing the request or authorization state.
  4. Respect Retry-After and use bounded exponential backoff for safe reads.
  5. Preserve idempotency keys while reconciling trading commands.
  6. Alert on repeated terminal failures without exposing provider payloads or credentials.

Next steps