Skip to content

Commit

Permalink
wrong api
Browse files Browse the repository at this point in the history
  • Loading branch information
StevoLOKE committed Sep 1, 2023
1 parent b11f669 commit 6823254
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,22 @@ class BaseClient {
});

if (res.ok) {
const body = await res.body();

// NB: Checking for null here first might be enough
// readable stream is null for a response with no body
if (res.body === null) return null;

// body stream to text
const text = await res.text();

// should never be null, don't necessarily need this line
if (body === null) return null;
if (text === null) return null;

// could be undefined (but most likely empty string), not json parse-able
// interpret empty body as the void response
if (!body || body === "") return;
if (!text) return;

// should be parse-able now if valid (returning null, string, array or object)
return JSON.parse(body);
return JSON.parse(text);
}

status = res.status;
Expand Down

0 comments on commit 6823254

Please sign in to comment.