Question

Lovable edge function says 'Edge Function returned a non-2xx status code' and nothing else

Solved · 611 viewsasked by adaeze

Lovable made an edge function send-invoice that calls Resend. From the app I get a toast with:

FunctionsHttpError: Edge Function returned a non-2xx status code

That's all. I don't know what goes wrong inside. It worked in the first version.

What I’ve tried

Asked Lovable to add more logging, it added console.log everywhere in the frontend. Redeployed the function via Lovable. Checked that the Resend key is in the Supabase secrets.

Comment
Supabase dashboard → Edge Functions → send-invoice → Logs. What does it say around the time of your click? jb_supa

2 answers

Marked as helpful by the asker
jb_supa

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_KEY is undefined: the secret has a different name than Deno.env.get(...) reads.
  • CORS: the browser sends an OPTIONS preflight 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.

Comment
Logs said "The from address domain is not verified". So it was Resend all along, I changed my sending domain last week. adaeze
Classic. Verify the new domain in Resend and you're done. jb_supa
chidi_eze

For deeper debugging: supabase functions serve runs the function locally, with secrets from supabase/functions/.env. You see stack traces right in your terminal.

Comment