scim-mcp / src /utils /responseBody.ts
chenhunghan's picture
fix: handle the case when fetch returns empty body
a65d39f unverified
raw
history blame contribute delete
344 Bytes
export async function readJsonBody(response: Response) {
const contentType = response.headers.get("content-type") ?? "";
if (!contentType.includes("application/json")) {
return {};
}
const text = await response.text();
if (!text.trim()) {
return {};
}
try {
return JSON.parse(text);
} catch {
return {};
}
}