Lovable Stripe checkout: "Edge Function returned a non-2xx status code"

Updated · by Zane

What the message really means

Lovable apps call backend functions through the Supabase library. When the function answers with an error status (anything outside 200 to 299), the library throws one fixed sentence: "Edge Function returned a non-2xx status code". Supabase describes this case as a function that ran and returned a 4xx or 5xx error.

The sentence is the same for every failure, so it cannot tell you what broke. A well known quirk of the library is that it does not put the function's own error text in that message, even when the function sent one. The detail is in the function's logs.

The checkout function ran and answered with an error status. The Supabase library turns that into one fixed sentence, which is all the page shows. The real reason is in the function logs; the usual causes are listed below.

Step 1: read the real error

  1. In Lovable, open More, then Cloud. Open the function logs there.
  2. If your app uses your own Supabase project, open the Supabase Dashboard instead, go to Functions, and select the checkout function. The Invocations tab shows each request with its status code. The Logs tab shows errors and your own log messages.
  3. Click the checkout button once, then reload the logs and find the newest red line.
  4. Also open Stripe, then Developers, then Logs. Lovable's guide points there for the error Stripe itself returned.

If the logs are empty, the request may never have reached your code. That points to case 3 or case 5 below. Copy the red line, because it decides which case you are in.

Case 1: the Stripe key is missing, wrong or revoked

With Lovable's Stripe connection, the key is saved as a backend secret named STRIPE_SECRET_KEY. If the function cannot read a key, or Stripe refuses it, the function fails and your customer sees the generic message. Lovable's guide says that if a stored key was revoked or its permissions changed, Stripe actions pause until you submit a working key.

  • In Lovable's chat, ask to update the Stripe key. It shows an Update Stripe secret key form. Enter the key there, never in the chat.
  • Use a restricted key (rk_) or secret key (sk_). Lovable's form does not accept publishable keys (pk_).
  • For your own Supabase project, the secret lives under the function secrets in the Supabase Dashboard.

Case 2: the price belongs to the other mode

Stripe test mode and live mode have separate prices, with different ids. A test price id used with a live key, or the reverse, makes Stripe refuse the request. Lovable's guide says price ids differ between modes and tells you to confirm products and prices exist in live mode before going live. The full walkthrough is in Stripe "No such price": test and live keys.

Case 3: the request is rejected before it runs

Supabase checks the caller's login token before it runs a function. Its documentation says verify_jwt is on by default. If your checkout needs a logged-in user and the visitor is logged out, the call can be refused before your code starts. I could not find a documented status code for this, so look at the Invocations tab: a refused request shows its status there with no log lines from your code.

Log in as a real user and try again. If the checkout is meant for logged-out visitors, ask Lovable to make that function callable without login.

Case 4: the request to Stripe is invalid

Sometimes your function reaches Stripe and Stripe says the request makes no sense. Stripe's API reference lists what Checkout needs:

  • mode is required, and Stripe says to pass subscription if any item is recurring. A one-time price in a subscription session, or the reverse, fails.
  • line_items is required for payment and subscription mode.
  • success_url is required for the hosted Checkout page.

The log line will quote Stripe's own message, so you can paste it into Lovable's chat together with the function name and ask for a fix.

Case 5: the browser blocks it (CORS)

Before calling a function, the browser sends a preflight request. The function must answer it with the right headers, and Supabase's documentation shows the function checking for that request first. If your function adds those headers only on success, an error response can look like a blocked request in the console, and the real message is hidden.

Here is the shape of a function that logs the real reason, returns it, and keeps the headers on errors too:

Checkout function (sketch)
const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
};

Deno.serve(async (req) => {
  // The browser sends this preflight request first
  if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });

  try {
    // ... create the Stripe Checkout Session here ...
    return new Response(JSON.stringify({ url: session.url }), {
      headers: { ...corsHeaders, "Content-Type": "application/json" },
    });
  } catch (e) {
    const message = e instanceof Error ? e.message : String(e);
    console.error("checkout failed:", message); // shows up in the function logs
    return new Response(JSON.stringify({ error: message }), {
      status: 400,
      headers: { ...corsHeaders, "Content-Type": "application/json" }, // keep CORS here too
    });
  }
});

On the page, read the answer instead of showing a fixed sentence:

Calling the function
const { data, error } = await supabase.functions.invoke("create-checkout", {
  body: { priceId },
});

if (error) {
  // For a non-2xx answer, the real response is on error.context
  const detail = await error.context?.json?.().catch(() => null);
  console.error("Checkout failed:", detail ?? error);
}

Supabase's error handling guide reads the body through error.context. Treat both snippets as a pattern to ask Lovable for, since your function name and fields will differ.

Test the fix

  1. Use a test-mode key and Stripe's test card 4242 4242 4242 4242, any future expiry and any CVC. Never test with a real card.
  2. Publish, then open the published app in a private window.
  3. Click the buy button and check Checkout opens, in a new tab if needed.
  4. Pay, and check the payment appears in Stripe.
  5. Check the customer's access changed. If it did not, see Stripe payment succeeded but the user is still on the Free plan.

FAQ

Is the error a Lovable bug?

Usually not. The text comes from the Supabase library that Lovable apps use to call backend functions. It means the function ran and answered with an error status. What went wrong inside is in the function's logs and in the response body.

The payment button does nothing and shows no error. Is it the same problem?

Often yes. If the function fails and the app never shows the message, the button just looks dead. Open the browser console and the function logs. Lovable's Stripe guide also notes that Checkout opens in a new tab, so a popup blocker can hide it. Allow popups for your app and try again.

Does it work in the Lovable preview?

Lovable's Stripe guide says the preview has no separate test environment, so a live key used there processes real payments. Use a test-mode key and Stripe's 4242 test card while you debug, and test on the published app.

Do I need to paste my Stripe key into the chat?

No. Lovable's guide says to enter the key only in its Connect Stripe form and never paste it into the chat. The key is stored as a backend secret and never placed in your app code.

Checklist

Still stuck?

Send me the app link and what's broken. The first look is free and you get a fixed quote before I touch anything.

Related guides