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).
Problem
getData()insrc/server/lib/simple-fin/data.tsandexchangeSetupToken()intokens.tscallfetch()but never checkresponse.okorresponse.status.data.ts (line ~37)
tokens.ts (line ~22)
Impact
.json()(returning HTML error page) or return an error payload that gets treated as valid account dataexchangeSetupTokencould return an error page body as the access URL, causing cryptic failures laterpolygon.tswhich properly checksresponse.okand returns typedPolygonResultFix
Add
response.okchecks and return meaningful errors, matching the pattern already used inpolygon.ts:Also validate the response shape before passing to
modelize()(e.g. checkdata.accountsis an array).