From f0966e7e6b5f29cd24e91c3852b96ea6163be74d Mon Sep 17 00:00:00 2001 From: William Oldham Date: Sat, 29 Aug 2026 17:39:36 +0100 Subject: [PATCH] feat(http): add JSON parsing to httpApi data response --- server/utils/httpApi.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/utils/httpApi.ts b/server/utils/httpApi.ts index 28f9264..e819396 100644 --- a/server/utils/httpApi.ts +++ b/server/utils/httpApi.ts @@ -27,7 +27,11 @@ export function useHttpApi(event: H3Event, token?: string): HttpApiFetch { if (response.statusCode >= 400) { const err = new Error(`Request failed with ${response.statusCode}`); try { - (err as any).data = await response.body.text(); + if (response.headers['content-type']?.includes('application/json')) { + (err as any).data = await response.body.json(); + } else { + (err as any).data = await response.body.text(); + } } catch { // It's already errored, we don't need to know the body }