The client error is deliberately vague; the real reason is in the function logs (dashboard → Edge Functions → your function → Logs / Invocations). Common ones with Lovable-generated functions:
RESEND_API_KEYis undefined: the secret has a different name thanDeno.env.get(...)reads.- CORS: the browser sends an
OPTIONSpreflight first. The function must answer it:
if (req.method === "OPTIONS") {
return new Response("ok", { headers: corsHeaders });
}- An exception because the request body is missing a field.
To see the error message in your app, read it from the response:
const { data, error } = await supabase.functions.invoke("send-invoice", { body });
if (error) console.error(await error.context.json());And have the function return { error: e.message } with status 400/500 in its catch block, so there's something to read.