Skip to content

Commit

Permalink
fix(client): 🐛 Don't try to decode non-JSON response as JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
CPlusPatch committed Jun 10, 2024
1 parent a87de7d commit d4f5895
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions client/lysand/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ export class BaseClient {
request: Request,
): Promise<Output<ReturnType>> {
const result = await fetch(request);
const isJson = result.headers
.get("Content-Type")
?.includes("application/json");

if (!result.ok) {
const error = await result.json();
const error = isJson ? await result.json() : await result.text();
throw new ResponseError(
`Request failed (${result.status}): ${
error.error || error.message || result.statusText
Expand All @@ -91,7 +94,7 @@ export class BaseClient {
}

return {
data: await result.json(),
data: isJson ? await result.json() : (await result.text()) || null,
headers: result.headers,
};
}
Expand Down

0 comments on commit d4f5895

Please sign in to comment.