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);