Your Lovable or Bolt app calls a Supabase Edge Function and the browser or the AI chat shows something like:
Edge Function returned a non-2xx status code
That line is not the real failure. It is the wrapper supabase-js shows when the function answered with any HTTP status outside the 200–299 success range (Supabase client error docs; Edge Function errors). Until you read the status code, the response body and the function logs, every retry is a guess.
This guide walks through what the wrapper means, how to pull out the underlying error, and how to fix the status codes Supabase documents for Edge Functions — especially the ones that show up in AI-built apps: 401, 500, CORS-looking failures, 404, 504 and 546. Related symptom guides: Lovable app not working and Stripe not working in Lovable or Bolt. Tool pages: /fix/supabase, /fix/lovable, /fix/bolt.
What the wrapper actually means
When your frontend calls supabase.functions.invoke(...), the SDK treats a 4xx or 5xx response as a FunctionsHttpError. The generic “non-2xx” string is what you see when the app (or the AI) only logs error.message instead of parsing the response body.
Supabase’s client docs split Edge Function failures into three error classes (supabase-js error handling):
| Error class | Meaning |
|---|---|
FunctionsHttpError | The function ran (or the platform returned an HTTP error) and the status was not 2xx |
FunctionsRelayError | A network problem between the client and Supabase |
FunctionsFetchError | The function could not be reached at all |
For FunctionsHttpError, the useful payload lives on error.context. Parse it:
import { FunctionsHttpError } from '@supabase/supabase-js'
const { data, error } = await supabase.functions.invoke('your-function')
if (error instanceof FunctionsHttpError) {
const body = await error.context.json()
console.error('status', error.context.status, 'body', body)
} else if (error) {
console.error(error)
}
That body is where messages such as "Missing authorization header", "Internal Server Error" or "Requested function was not found" appear. The status code on error.context is what you map to the sections below.
Read the real error: logs plus the response body
Two places tell you what happened. Use both.
1. The HTTP response. Status code and JSON body, via error.context as above, or via the Network tab in DevTools on the failed /functions/v1/... request.
2. The function logs. Supabase’s logging guide splits these into Invocations (request/response, status, duration) and Logs (uncaught exceptions, console.log / console.error, boot and shutdown events) under Edge Functions in the dashboard (Supabase: Edge Functions logging).
Where are logs in Lovable Cloud?
On Lovable’s built-in backend, open More → Settings → Logs and pick a function-related log type such as Function edge logs, Edge logs or Function logs. You can also open More → Database → Manage → Edge functions, pick the function, then use View logs to jump into Logs scoped to that function (Lovable: Logs, Lovable: Edge functions). The relative time picker covers windows as far back as five days; click Refresh because the view does not stream live.
If the project uses your own Supabase account instead of Lovable Cloud, open that project’s Edge Functions section in Supabase and read Invocations plus Logs there (Lovable: Connect to Supabase).
Where are logs in Bolt?
On Bolt Cloud, open the database icon, then Server Functions, and open View Logs on the function (Bolt retains roughly one hour of entries). Or open Logs from the same database menu and choose a server-function log type (Bolt: Server functions, Bolt: Database logs). With your own Supabase project connected, the matching function is also visible in your Supabase project UI.
Status codes at a glance
Taken from Supabase’s status-code reference (status codes):
| Code | What Supabase says it means | First place to look |
|---|---|---|
| 2xx | Function returned a success status | Nothing to fix |
| 401 | JWT check failed, or your code returned 401 | Auth header / verify_jwt |
| 404 | Function name or URL wrong, or bundle missing | Deployed name vs invoke name |
| 405 | Unsupported HTTP method | Use GET/POST/PUT/PATCH/DELETE/OPTIONS |
| 500 | Uncaught exception, or your code returned 500 | Function logs / missing secret |
| 503 | Isolate did not boot (BOOT_ERROR), or platform issue | Syntax/import errors in logs |
| 504 | No response within the request timeout (150s max) | Slow queries or external APIs |
| 546 | Resource limit hit (WORKER_RESOURCE_LIMIT) | CPU or memory in logs |
Note the split between 504 and 546. A timeout is 504. Exhausting CPU or memory is 546 (about 2 seconds of CPU and 250 MB of memory per isolate in Supabase’s resource-limit guide). Older write-ups collapse both into “timeout”; the logs name which one you have (timeout guide; resource-limit guide).
401 and missing authorization header
A 401 means either the platform’s built-in JWT check rejected the request before your code ran, or your handler returned 401 on purpose (Edge Function 401 error response).
Platform messages look like:
{ "code": 401, "message": "Missing authorization header" }
or "Invalid JWT" / "Invalid Token or Protected Header formatting".
When verify_jwt is on (the default), the platform expects a valid user JWT on the Authorization: Bearer ... header before your handler runs (Authorization headers). Calls made through supabase.functions.invoke while the user is signed in send that JWT plus the project’s publishable key on apikey. Calls made with raw fetch or curl need the header added by hand.
Should I set verify_jwt = false?
Only when the caller cannot send a Supabase user JWT. Webhooks from Stripe, GitHub and similar services do not carry your app’s session token, so those functions need verify_jwt = false in supabase/config.toml (or the dashboard / --no-verify-jwt deploy flag) and your own verification of the webhook signature in the function body (Securing Edge Functions, Bolt: Integrations issues).
For a function your signed-in app calls with supabase.functions.invoke, leave the platform check on (or replace it with an explicit auth: 'user' check in @supabase/server). Turning it off “to make the 401 go away” without adding another check leaves the endpoint open. Supabase’s 401 guide also notes that the legacy platform check does not understand newer asymmetric API key formats the same way; if you see incompatible-key failures, disable the legacy check and verify credentials in your code instead of disabling auth entirely.
500: missing secret or uncaught exception
A 500 is either an uncaught JavaScript error (WORKER_ERROR) or a status your code set itself (500 troubleshooting). The response body "Internal Server Error" points at an unhandled throw. Open the function’s Logs tab for the stack trace (TypeError, ReferenceError, and so on).
In AI-built apps, one cause to check is a secret that was never set in production. Edge Functions read secrets with Deno.env.get('NAME'). Local values live in supabase/functions/.env; production values are set in the dashboard under Edge Function Secrets or with supabase secrets set (Environment variables / secrets). A missing Stripe, Resend or OpenAI key shows up as a throw when the function tries to use undefined.
On Lovable Cloud, secrets are managed in the project’s Secrets UI and never belong in frontend code (Lovable: Edge functions). On Bolt, add them under the database Secrets screen (or the Secrets page for Edge Functions in your own Supabase project); Bolt’s docs say a new secret is available without a redeploy (Bolt: Integrations issues).
Wrap risky work in try/catch, log with console.error, and return a JSON body with a clear message and an appropriate status so the next failure is readable from error.context.
CORS errors (and why the browser blames CORS)
Browsers send an OPTIONS preflight before cross-origin calls. Your function must answer that preflight and must attach CORS headers to success and error responses. Supabase’s CORS guide shows handling OPTIONS and returning corsHeaders on every response, including 4xx paths; newer @supabase/supabase-js versions export a shared corsHeaders object you can import from the SDK cors entry, and withSupabase can handle preflight for you (CORS guide).
Why do I get a CORS error when the function is the problem?
Two documented cases look like CORS in the browser even when the root cause is elsewhere:
- A platform 404. Supabase’s 404 guide warns that browsers misreport platform 404s as generic CORS failures, and
supabase-jsmay only show a generic “failed to send” message for the Edge Function call. Confirm with logs or a non-browser request; the platform body for a missing function is"Requested function was not found"(404 troubleshooting). - An error thrown before CORS headers are set. Supabase’s 500 guide notes that if the handler returns or throws before the
OPTIONS/ CORS branch runs, the browser reports a CORS failure even though the real issue is a crash or an early return (500 troubleshooting).
So treat a CORS message as “open the function logs and the Network status code,” not as proof that only headers are wrong.
404, 503, 504 and 546
404. Wrong function name in the URL, a typo in functions.invoke('...'), or a deploy whose bundle the runtime cannot find (NOT_FOUND vs NOT_FOUND_FUNCTION_BLOB). Redeploy from the dashboard or supabase functions deploy FUNCTION_NAME, and compare the name character-for-character (404 troubleshooting).
503. BOOT_ERROR means the isolate never started: syntax errors, bad imports, or redeclared constants. Filter logs for boot failures. A 503 can also be a status your code returned, or a platform incident (503 troubleshooting).
504. The function did not produce a response within the maximum execution time (150 seconds; not configurable). Slow database queries, sequential external API calls and unbounded loops show up in the logs — shorten the work, run independent fetches in parallel, or move long jobs off the request path. Details: timeout troubleshooting.
Resource limit (546). CPU or memory allotment exceeded (WORKER_RESOURCE_LIMIT). Logs say Memory limit exceeded or CPU Time exceeded. Shrink payloads, drop heavy libraries, or split the work across smaller functions. Details: resource-limit troubleshooting.
Why does preview work but not live?
Check three production-only gaps:
- Secrets set locally but not in production (or set in Lovable/Bolt Secrets under a different name than
Deno.env.getexpects). - A function deployed in the editor preview path but not to the live project, or a name mismatch between the invoke call and the deployed function.
- Auth: preview may call the function while you are signed in; a live page hit while signed out, or a webhook with no JWT, hits the 401 path above.
Reproduce the live call once from DevTools or curl, then compare that status to the production logs for the same minute.
Stripe webhooks and this error
Stripe webhook handlers are a special case of 401 plus secrets. Stripe does not send a Supabase JWT, so the webhook function needs verify_jwt = false and signature verification with your webhook signing secret. Wrong signing secrets, test vs live key mix-ups and missing STRIPE_SECRET_KEY values all surface as non-2xx responses from the Edge Function.
Work through the full Stripe checklist in Stripe not working in a Lovable or Bolt app. Come back here when the Stripe dashboard shows a delivery failure and you need the status-code map above.
Stop the agent loop: give it the log line
Why does the AI keep “fixing” without success?
The agent only sees the wrapper string you pasted. Without the status code and log line, it rewrites CORS headers, toggles verify_jwt, and regenerates the same function while the real failure (missing secret, wrong name, uncaught TypeError) stays put. Lovable’s docs explicitly say to paste the error from View logs into the project chat (Lovable: Edge functions). Bolt’s integrations guide points at the same pattern for CORS, JWT and secrets (Bolt: Integrations issues).
Copy a prompt like this instead of “fix the edge function error”:
supabase.functions.invoke('FUNCTION_NAME') fails with FunctionsHttpError.
HTTP status from error.context: STATUS_HERE
Response body: PASTE_JSON_BODY_HERE
Function log line (same timestamp): PASTE_LOG_LINE_HERE
Fix the root cause for that status. Do not disable auth unless this is a webhook
that verifies a provider signature. Show the code diff before applying it.
If you are still stuck after one focused pass with the real log line, inahei.pro can connect you with a vetted senior engineer who reads the logs and lands a fix. Fixed price, agreed upfront.
Comments