Skip to content

reliability: SimpleFin API calls don't validate HTTP response status #184

@moltboie

Description

@moltboie

Problem

getData() in src/server/lib/simple-fin/data.ts and exchangeSetupToken() in tokens.ts call fetch() but never check response.ok or response.status.

data.ts (line ~37)

const response = await fetch(`${url}/accounts?${params.toString()}`, {
  headers: { Authorization: `Basic ${credentials}` },
});
// No status check!
const data: ResponseData = await response.json();

tokens.ts (line ~22)

const response = await fetch(setupUrl, { method: "POST", headers: { "Content-Length": "0" } });
// No status check!
return await response.text();

Impact

  • A 4xx/5xx response will either throw on .json() (returning HTML error page) or return an error payload that gets treated as valid account data
  • exchangeSetupToken could return an error page body as the access URL, causing cryptic failures later
  • Compare with polygon.ts which properly checks response.ok and returns typed PolygonResult

Fix

Add response.ok checks and return meaningful errors, matching the pattern already used in polygon.ts:

if (!response.ok) {
  throw new Error(`SimpleFin API error: ${response.status} ${response.statusText}`);
}

Also validate the response shape before passing to modelize() (e.g. check data.accounts is an array).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions