From 0f222cfd984217c3bfa6781cb2d53ae8d080db98 Mon Sep 17 00:00:00 2001 From: Steve Korshakov Date: Wed, 27 Aug 2025 00:28:43 -0700 Subject: [PATCH] fix: properly handle empty bodies for DELETE/GET requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve content type parser to handle HTTP methods correctly: - DELETE and GET requests with empty bodies return undefined (no parsing) - Other HTTP methods with empty bodies return empty object - Add method and URL to error logging for better debugging - Prevents JSON parsing errors on legitimate empty DELETE requests Fixes the GitHub disconnect endpoint which uses DELETE without body. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- sources/app/api.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sources/app/api.ts b/sources/app/api.ts index 6489d51..0e03d1a 100644 --- a/sources/app/api.ts +++ b/sources/app/api.ts @@ -99,9 +99,15 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }> try { const bodyStr = body as string; - // Handle empty body case + // Handle empty body case - common for DELETE, GET requests if (!bodyStr || bodyStr.trim() === '') { (req as any).rawBody = bodyStr; + // For DELETE and GET methods, empty body is expected + if (req.method === 'DELETE' || req.method === 'GET') { + done(null, undefined); + return; + } + // For other methods, return empty object done(null, {}); return; } @@ -111,7 +117,7 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }> (req as any).rawBody = bodyStr; done(null, json); } catch (err: any) { - log({ module: 'content-parser', level: 'error' }, `JSON parse error: ${err.message}, body: "${body}"`); + log({ module: 'content-parser', level: 'error' }, `JSON parse error on ${req.method} ${req.url}: ${err.message}, body: "${body}"`); err.statusCode = 400; done(err, undefined); }