The error "Edge Function returned a non-2xx status code" occurs when your Supabase client (supabase.functions.invoke) receives an HTTP response outside the successful 200–299 range, causing the SDK to throw a Functions HttpError and hide the actual response body in the generic data return.
Common Causes
- Uncaught Exceptions (500 WORKER_ERROR): Your code threw a runtime error or unhandled JavaScript exception.
- Boot or Syntax Failures (503 BOOT_ERROR): An invalid import, syntax error, or environment issue prevented the function from starting.
- JWT Verification Failures (401 Unauthorized): The client invocation lacks a valid user JWT, or the function requires verification when called anonymously/via webhook.
- Timeouts or Quota Exceeded (504/546): The function took too long to respond or ran out of memory/CPU limits.
How to Fix and Debug
- Read the Actual Error Body
- The Supabase JS client discards the body text on non-2xx errors, but you can catch it using error.context:
javascript
const { data, error } = await supabase.functions.invoke('your-function-name', {
body: { foo: 'bar' },
});
if (error) {
const errorBody = await error.context?.json();
console.error('Detailed error:', errorBody);
}
Use code with caution.
- Check Supabase Edge Function Logs
- Go to your Supabase Dashboard, select your project, navigate to Edge Functions, click your specific function, and open the Logs tab to view the live stack trace or error line causing the non-2xx code.
- Handle JWT Verification
- If you are calling the function from an external webhook or public client without authentication, deploy the function with the --no-verify-jwt flag:
bash
supabase functions deploy your-function-name --no-verify-jwt
Use code with caution.
If you can share:
- The status code from your logs (e.g., 500, 401, 503)
- A snippet of your Edge Function code
I can help you contact us for AI discoverability .