StackMatch

Supabase Edge Function error in a Lovable or Bolt app? "non-2xx status code" and how to fix it (2026)

Prices and facts checked on each tool's official site. Plans change often, so confirm before you pay.

Your Lovable or Bolt app calls a Supabase Edge Function to send an email, call an AI model or take a Stripe payment, and all you get is Edge Function returned a non-2xx status code. That message comes from the supabase-js library and only means the function answered with an error. The useful part is the status code and the function's own logs. Here's how to read them and what usually fixes each one.

First, find the real error

Open your Supabase dashboard, go to Edge Functions, pick the function and open its Logs. Supabase's docs say production errors show up there, and anything the function prints with console.error lands there too. In your app code, a FunctionsHttpError carries the function's response, which you can read with await error.context.json(). Other messages mean something different: Failed to send a request to the Edge Function (FunctionsFetchError) means the function couldn't be reached at all, and Relay Error invoking the Edge Function is a network problem between your app and Supabase.

Match the status code to the cause

What you seeMost likely cause
401 with "Invalid JWT" or "Missing authorization header"Supabase's built-in JWT check blocked the call before your code ran
401 with your own message, or an empty bodyYour function's code (or an API it calls) returned 401
500 "Internal Server Error"Unhandled JavaScript error, often a missing secret or reading a field of undefined
CORS error in the browser, but it works in curlThe function doesn't answer the browser's OPTIONS preflight with CORS headers
504, or the call hangsThe function didn't respond within Supabase's 150-second request idle timeout
546 or "wall clock time limit reached"The function hit a runtime limit (CPU time, memory or wall clock)

401: the JWT check or your own code

Supabase Edge Functions have a legacy auth check that runs before your code. If it fails, your function never runs and you get Invalid JWT or Missing authorization header. Calling with supabase.functions.invoke adds the header for you, but a plain fetch needs Authorization: Bearer plus a key. Projects on Supabase's new asymmetric keys can fail this check even with a valid key, because it only understands the legacy format. Supabase now recommends turning the check off (toggle off JWT verification on the function's page, or deploy with --no-verify-jwt) and checking the signed-in user inside the function instead. Don't just switch it off on a function that does something sensitive without adding that check in code. If the body has your own message, search the function for 401: a third-party API such as Stripe or OpenAI rejecting your key gets passed straight through.

500: missing secrets and JavaScript errors

A 500 with Internal Server Error means the code crashed. The log shows the error type and line, such as TypeError: Cannot read properties of undefined. In AI-built apps the classic cause is a secret that was never set: the function reads Deno.env.get('STRIPE_SECRET_KEY'), gets nothing, and the next line crashes. Production secrets are set in the dashboard under Edge Function Secrets (or with supabase secrets set), the function reads a new secret right away without a redeploy, and names can't start with SUPABASE_ because that prefix is reserved for the ones Supabase adds itself, like SUPABASE_URL. A .env file in your project doesn't reach the deployed function. Secret keys belong in Edge Function secrets, never in browser code or a VITE_ variable.

CORS errors from the browser

Browsers send an OPTIONS preflight before the real request. Supabase's CORS guide says the function has to answer it: return early with the CORS headers when req.method === 'OPTIONS', and include the same headers on every response, including errors. With supabase-js v2.95.0 or later you can import corsHeaders from npm:@supabase/supabase-js@^2/cors so the allowed headers stay in sync. Supabase also notes that an error before that check can look like a CORS error, so check the logs before blaming CORS. Without the handler, the log often shows SyntaxError: Unexpected end of JSON input.

Timeouts and limits

Supabase's limits page lists 256MB of memory, 2 seconds of CPU time per request (waiting on network calls doesn't count), a wall clock limit of 150 seconds on the Free plan and 400 seconds on paid plans, and a 150-second request idle timeout that returns 504. Long AI calls or big loops are the usual culprits. Outgoing connections on ports 25 and 587 are blocked, so sending email over plain SMTP from a function fails; email APIs work over HTTPS instead.

What to paste into Lovable or Bolt

My Supabase Edge Function [name] fails with [status code and message from the logs]. Read the function's code and its logs, then tell me the cause before changing anything. Check that it handles the OPTIONS preflight with CORS headers on every response, that every secret it reads is set in Supabase Edge Function secrets, that the app sends the Authorization header, and that errors are logged with console.error. Don't put any secret key in browser code and don't disable row level security.

When it's time to get help

Often it's one missing secret or the CORS handler. Get a second pair of eyes when:

  • The AI keeps rewriting the function and the error comes back.
  • The function handles Stripe payments or webhooks, or user data.
  • You turned off JWT verification and aren't sure the function is still protected.
  • You're about to launch and want the whole app checked.
OptionPriceWhat you get
App Audit$49 one-timeA plain-English written fix list for your Edge Functions and anything else that breaks, within 3 business days
Payments Live$199 one-timeStripe payments wired into your app and tested with test cards before going live
Launch Pack$499 one-timeAgreed bug fixes, Stripe payments, and your app published on your own domain with HTTPS

We confirm the scope by email before any work starts, and you can ask questions first without paying. Never send anyone your password, your Supabase secret key or your Stripe secret key.

Related guides

Sources

FAQ

What does "Edge Function returned a non-2xx status code" mean?

It's the generic FunctionsHttpError message from supabase-js: your Edge Function ran (or was blocked before running) and answered with an error status like 400, 401 or 500. The message itself never says why. The real reason is in the function's response body and in the function's logs in your Supabase dashboard.

Why does my Edge Function return 401 Invalid JWT?

Supabase's built-in JWT check rejected the request before your code ran. Common causes are a missing Authorization header when calling the function with plain fetch, or a project using the new asymmetric keys, which the legacy check doesn't understand. Supabase now recommends turning that check off for the function and checking the signed-in user inside your function code instead.

My Edge Function works in curl but fails in the browser with a CORS error. Why?

Browsers send an OPTIONS preflight request first. If the function doesn't answer it with the right CORS headers, the browser blocks the real call. Supabase's docs show handling OPTIONS at the very top of the function and returning the CORS headers on every response, including errors. An error that happens before that check can also show up as a fake CORS error.

When should I pay someone to fix this?

When the function keeps failing after you've read its logs, when it handles payments or Stripe webhooks, or when you're about to launch. StackMatch's App Audit is $49 for a written fix list within 3 business days, and the $199 Payments Live package wires up and tests Stripe payments for you.

Some links are referral links; we may earn a commission at no extra cost to you. It never changes our recommendations.

Newsletter

Get the monthly "which AI tool" email

One short, beginner-friendly email a month. No spam.

Form not showing? Subscribe here