Edge Function returned a non-2xx status code
On this page
Short answer
Your Edge Function answered with an error status, and supabase-js replaced the details with one generic sentence. The real status and response body are still on error.context. Log error.context.status and the body text, then fix what they point to: bad input, a crash in your function, a function that won't start, or a timeout.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.
The exact error you'll see
supabase.functions.invoke() returns a FunctionsHttpError with this message:
Edge Function returned a non-2xx status code
The message never changes. Logging only error.message hides the useful part.
Applies to
- Any app calling
supabase.functions.invoke()from supabase-js - Lovable, Bolt and Cursor apps that call Supabase Edge Functions
- Only
FunctionsHttpError. supabase-js has separate error classes for a relay failure (FunctionsRelayError) and a failed fetch (FunctionsFetchError)
Why it happens
- The function returned a status outside 200–299. In supabase-js,
if (!response.ok)creates aFunctionsHttpErrorthat keeps the response, andinvoke()returns it withdata: null. - Your code returned an error on purpose. Supabase tells you to "Return 400 for bad user input, 404 when something doesn't exist, 500 for server errors."
- The function crashed. An uncaught exception ends as a 500.
- The function didn't start. Supabase lists "Syntax errors preventing the function from loading" as a cause of a 503.
- The function ran too long. A 504 Gateway Timeout. Supabase suggests "breaking large operations into smaller chunks."
How to fix it, step by step
- Find the failing
invoke()call. Check the returnederror, not only a surroundingtry/catch, becauseinvoke()returns the error instead of throwing it. - Log the real status and body. This adapts Supabase's error-handling example to read the body as text, which works whatever format the function sent back:
import { FunctionsHttpError } from '@supabase/supabase-js'
const { data, error } = await supabase.functions.invoke('hello', {
body: { foo: 'bar' },
})
if (error instanceof FunctionsHttpError) {
console.log(error.context.status)
console.log(await error.context.text())
}
If your function always returns JSON, Supabase's own example uses await error.context.json() instead. Read the body once: MDN says text() throws if the body "is disturbed or locked."
- Match the status to the cause:
- 400: your function rejected the input. Fix what its message names.
- 500: your function threw. Open its logs and fix that line.
- 503: the function failed to start. Check for syntax and import errors, then redeploy.
- 504: it ran too long. Speed up slow queries or outside API calls, or split the work.
- 401: see Supabase Edge Function 401 (verify JWT). For a browser CORS error, see Supabase Edge Function CORS error.
- Open the function's logs in the Supabase dashboard. They capture
console.log,console.warnandconsole.erroroutput and uncaught exceptions. Add a log line around the step you suspect, reproduce once, and read it. - Return clear errors from your function. Supabase recommends the right status code for each case because it "lets client apps handle different error types appropriately."
- Redeploy the function and repeat the exact request that failed.
What the docs don't spell out
json()can hide the real error. If the function sent back HTML or plain text,error.context.json()throws aSyntaxErrorbecause the body "cannot be parsed as JSON." Start withtext(). (Response.json() (opens in a new tab))- The dashboard won't show you the body later. Supabase: "Request and response bodies are not logged or retained." Capture the body in your client log while you reproduce, and don't log secrets. (Edge Function logging (opens in a new tab))
How to check it worked
- The same
invoke()call returnsdataanderrorisnull. - A deliberately bad request still returns a clear status and message you can show the user.
- The function's logs show no new exception for that request.
Sources
- https:/
/ : exact message and thegithub. com/ supabase/ supabase- js/ blob/ master/ packages/ core/ functions- js/ src/ types. ts (opens in a new tab) FunctionsHttpError,FunctionsRelayErrorandFunctionsFetchErrorclasses - https:/
/ :github. com/ supabase/ supabase- js/ blob/ master/ packages/ core/ functions- js/ src/ FunctionsClient. ts (opens in a new tab) !response.okcheck, error returned withdata: null - https:/
/ : client example withsupabase. com/ docs/ guides/ functions/ error- handling (opens in a new tab) error.context.json(), status code guidance - https:/
/ : 500, 503 and 504 causes, splitting large operationssupabase. com/ docs/ guides/ functions/ status- codes (opens in a new tab) - https:/
/ : what logs capture, bodies not retainedsupabase. com/ docs/ guides/ functions/ logging (opens in a new tab) - https:/
/ :developer. mozilla. org/ en- US/ docs/ Web/ API/ Response/ text (opens in a new tab) text()and the disturbed or locked body error - https:/
/ :developer. mozilla. org/ en- US/ docs/ Web/ API/ Response/ json (opens in a new tab) json()throwsSyntaxErroron non-JSON
Related fixes
Tool to consider: Supabase.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.