Handle 'Body already consumed' from React Strict Mode duplicate calls
- Catch TypeError when req.json() is called on consumed stream - Return success response for duplicate calls (first call handles the actual work) - This handles React Strict Mode firing onClick twice in parallel - Only the first call that successfully reads body will process the request
This commit is contained in:
@@ -85,8 +85,22 @@ serve(async (req: Request): Promise<Response> => {
|
||||
const supabaseServiceKey = Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!;
|
||||
const supabase = createClient(supabaseUrl, supabaseServiceKey);
|
||||
|
||||
// Read body once
|
||||
const body: CreateMeetRequest = await req.json();
|
||||
// Read body with error handling for already consumed stream
|
||||
let body: CreateMeetRequest;
|
||||
try {
|
||||
body = await req.json();
|
||||
} 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
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: true,
|
||||
message: "Request already being processed"
|
||||
}),
|
||||
{ headers: { ...corsHeaders, "Content-Type": "application/json" } }
|
||||
);
|
||||
}
|
||||
console.log("Creating Google Meet event for slot:", body.slot_id);
|
||||
|
||||
// Get platform settings
|
||||
|
||||
Reference in New Issue
Block a user