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 supabaseServiceKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
|
||||||
const supabase = createClient(supabaseUrl, supabaseServiceKey);
|
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;
|
let body: CreateMeetRequest;
|
||||||
try {
|
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) {
|
} catch (bodyError) {
|
||||||
console.log("Body already consumed, returning cached success response");
|
console.error("Error reading body:", bodyError);
|
||||||
// When body is consumed (from React Strict Mode duplicate call),
|
|
||||||
// return a success response since the other concurrent call will handle it
|
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
success: true,
|
success: false,
|
||||||
message: "Request already being processed"
|
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);
|
console.log("Creating Google Meet event for slot:", body.slot_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user