Fix body consumption: use req.text() instead of req.json()
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 <noreply@anthropic.com>
This commit is contained in:
@@ -85,20 +85,21 @@ serve(async (req: Request): Promise<Response> => {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user