Skip to content

Commit ab86276

Browse files
committed
zodfetch fixes
1 parent a2293b6 commit ab86276

File tree

1 file changed

+9
-1
lines changed
  • packages/core/src/v3/apiClient

1 file changed

+9
-1
lines changed

packages/core/src/v3/apiClient/core.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ async function _doZodFetchWithRetries<TResponseBodySchema extends z.ZodTypeAny>(
229229
}
230230
}
231231

232-
const jsonBody = await response.json();
232+
const jsonBody = await safeJsonFromResponse(response);
233233
const parsedResult = schema.safeParse(jsonBody);
234234

235235
if (parsedResult.success) {
@@ -269,6 +269,14 @@ async function _doZodFetchWithRetries<TResponseBodySchema extends z.ZodTypeAny>(
269269
}
270270
}
271271

272+
async function safeJsonFromResponse(response: Response): Promise<any> {
273+
try {
274+
return await response.clone().json();
275+
} catch (error) {
276+
return;
277+
}
278+
}
279+
272280
function castToError(err: any): Error {
273281
if (err instanceof Error) return err;
274282
return new Error(err);

0 commit comments

Comments
 (0)