From 3f8c2b7c01d4ff4cc0e2732f64482e159b59f953 Mon Sep 17 00:00:00 2001 From: dwindown Date: Tue, 23 Dec 2025 16:14:56 +0700 Subject: [PATCH] Fix body consumption: use req.text() instead of req.json() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using req.text() first then parsing JSON gives us more control and avoids stream consumption issues with Deno/Supabase edge functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../functions/create-google-meet-event/index.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/supabase/functions/create-google-meet-event/index.ts b/supabase/functions/create-google-meet-event/index.ts index 1322a02..dfe5f0b 100644 --- a/supabase/functions/create-google-meet-event/index.ts +++ b/supabase/functions/create-google-meet-event/index.ts @@ -85,20 +85,21 @@ serve(async (req: Request): Promise => { const supabaseServiceKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!; const supabase = createClient(supabaseUrl, supabaseServiceKey); - // Read body with error handling for already consumed stream + // Clone the request to avoid stream consumption issues + // Read body text first, then parse JSON let body: CreateMeetRequest; try { - body = await req.json(); + const bodyText = await req.text(); + console.log("Raw body text:", bodyText.substring(0, 100) + "..."); + body = JSON.parse(bodyText); } catch (bodyError) { - console.log("Body already consumed, returning cached success response"); - // When body is consumed (from React Strict Mode duplicate call), - // return a success response since the other concurrent call will handle it + console.error("Error reading body:", bodyError); return new Response( JSON.stringify({ - success: true, - message: "Request already being processed" + success: false, + message: "Invalid request body: " + (bodyError as Error).message }), - { headers: { ...corsHeaders, "Content-Type": "application/json" } } + { status: 400, headers: { ...corsHeaders, "Content-Type": "application/json" } } ); } console.log("Creating Google Meet event for slot:", body.slot_id);