mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
fix(client): 🐛 Don't try to decode non-JSON response as JSON
This commit is contained in:
parent
a87de7d20b
commit
d4f5895dbf
|
|
@ -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
|
||||
|
|
@ -91,7 +94,7 @@ export class BaseClient {
|
|||
}
|
||||
|
||||
return {
|
||||
data: await result.json(),
|
||||
data: isJson ? await result.json() : (await result.text()) || null,
|
||||
headers: result.headers,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue