oazapfts client returns status 200 with data: null when the response body fails to download
A SvelteKit app using an oazapfts-generated SDK (@oazapfts/runtime 1.2.0) reported sporadic crashes in Safari such as TypeError: null is not an object (evaluating 'i.effective_child_display') inside load functions. The code only dereferenced the value after the SDK's ok() helper had resolved, so the response was a 2xx and should have carried the JSON object. Breadcrumbs showed the fetch for that endpoint logged status_code: 200, and the very next request failed at the network level. Every event came right after a connection drop or a tab waking from sleep. The API never returns an empty or null body for that route, there is no service worker, and no error was thrown anywhere; the caller simply received null with a success status, so retry and offline handling keyed on thrown errors never ran.
Root cause is in @oazapfts/runtime (1.2.0, index.js). fetchText reads the body inside an empty catch:
const t = await doFetch(url, opts);
let s;
try { s = await t.text(); } catch {}
return { status: t.status, headers: t.headers, contentType: t.headers.get('content-type'), data: s };and fetchJson then does data: c ? JSON.parse(c) : null for JSON content types. So when the headers arrive (status 200) but the body read rejects (connection dropped mid-body, request aborted after headers, device went offline), the failure is swallowed and the call resolves to {status: 200, data: null}. ok() only checks the status, so it returns null as if it were the success body. fetchBlob has the same empty catch.
A literal JSON null body is indistinguishable at the call site, so checking for null after the fact is ambiguous. Fix it where the request is made: pass a custom fetch in the SDK options (per call or via defaults.fetch) that reads the body itself and hands oazapfts an already-buffered Response, so a failed read throws like any other network error:
const NULL_BODY_STATUS = [204, 205, 304]; // Response() rejects a body for these
async function bufferedFetch(input: RequestInfo | URL, init?: RequestInit) {
const res = await fetch(input, init);
const body = NULL_BODY_STATUS.includes(res.status) ? null : await res.arrayBuffer();
return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
}If the wrapper also owns an AbortController timeout, keep the body read inside the timed region; clearing the timer as soon as headers arrive leaves a stalled body with no deadline. Status: root cause established by reading the runtime source and matching it to the production events; the wrapper is the planned fix and had not shipped when this was written.