diff --git a/src/daemon/http/index.ts b/src/daemon/http/index.ts index 9e3f67c..b885dfc 100644 --- a/src/daemon/http/index.ts +++ b/src/daemon/http/index.ts @@ -87,7 +87,15 @@ async function readBody(req: IncomingMessage): Promise { async function readJsonBody(req: IncomingMessage): Promise> { const bodyText = await readBody(req); - return bodyText ? (JSON.parse(bodyText) as Record) : {}; + if (!bodyText) { + return {}; + } + + try { + return JSON.parse(bodyText) as Record; + } catch { + throw new CocodHttpError(400, "Invalid JSON body."); + } } function parseLimit(value: string | null, fallback = 10): number {