Spaces:
Sleeping
Sleeping
| 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 {}; | |
| } | |
| } | |