Fix guide · updated 2026-11-09
Edge Function returned a non-2xx status code: read the real error and fix it
Edge Function returned a non-2xx status code · FunctionsHttpError · Failed to send a request to the Edge Function
Your app shows Edge Function returned a non-2xx status code, often in a red pop-up after you click a button that sends an email, takes a payment or calls an AI service. Your function didn't write that message. The Supabase client in your app did, and it only means the function answered with an error code instead of a success (2xx means 200 to 299). The function's real answer, the one that names the problem, is one step away. Read it first.
1. Read the status code and the real error
In Chrome, open the developer tools (Ctrl + Shift + I on Windows, Cmd + Option + I on a Mac), click the Network tab, then make the error happen again. Click the request whose address contains /functions/v1/ followed by your function's name. The status code is at the top of its Headers tab, and what the function sent back is in the Response tab. The console shows the same code in a red line that starts like this:
Failed to load resource: the server responded with a status of 500
Error responses can also carry an sb-error-code header with a name for the problem, such as BOOT_ERROR or UNAUTHORIZED_NO_AUTH_HEADER.
To print the function's answer from your app instead, check the error's type and read error.context, which holds the function's response:
import { FunctionsHttpError } from '@supabase/supabase-js'
const { data, error } = await supabase.functions.invoke('send-email', { body })
if (error instanceof FunctionsHttpError) {
console.error('Function answered', error.context.status, await error.context.text())
}
Supabase's docs read the answer with .json(). That fails when the answer is plain text, such as Internal Server Error, so .text() is the safer choice. We tested both with the current Supabase client in Chrome. Then open the function's logs, which hold the full error and the line it came from:
- Lovable: More → Database → Manage → Edge functions, click the function, then View logs. Logs don't update by themselves, so click Refresh after the error.
- Bolt: the database icon at the top of your project, then Server Functions, then View Logs on the function. Bolt only keeps the last hour.
- Your own Supabase project: the Edge Functions section of the dashboard, then your function. Invocations lists each request with its status code, and Logs shows crashes and your function's own messages.
Then match the status code below. A 400, 403 or 422 usually comes from your function's own code, which refused the request on purpose, and its answer says why.
2. 401: the function refused the caller
If the answer is Missing authorization header (full guide), Invalid JWT or Invalid Token or Protected Header formatting, your code never ran. By default, Supabase checks every call for a signed-in user's token before it reaches your function, and this call didn't pass. The usual reasons:
- Nobody is signed in, or the session expired. Sign out and back in, then try again. If the function serves visitors who aren't signed in, like a contact form, it shouldn't require a user at all: see the last point.
- The app calls the function with
fetchinstead ofsupabase.functions.invoke. The Supabase client adds the user's token for you, and a plainfetchdoesn't. Ask your AI tool to switch the call tosupabase.functions.invoke. - The caller isn't your app: Stripe, another webhook, a scheduled job. They don't have a user's token. Turn the check off for that function only, and make the function check the caller itself, the way Stripe webhooks are checked with their signature. In a Supabase project, the setting is on the function's page in the dashboard, or in
supabase/config.toml:
[functions.stripe-webhook]
verify_jwt = false
Turning the check off makes the function public: anyone who finds its address can call it. Only do it for a function that checks its caller in its own code. If every call gets a 401 even with a signed-in user, Supabase's troubleshooting page for 401s covers key formats the built-in check rejects. Its fix is the same: turn the check off for that function and verify the user in the function's code.
If the 401 comes with a message your own code wrote, the function ran and refused the request on purpose. Its code says why.
3. 500: the function's code failed
A 500 means your function ran and hit an error. If the answer is just Internal Server Error, the code crashed on an error it didn't catch. Otherwise the answer is your function's own error message. Either way, the log has the details. The usual causes:
- A missing secret. Functions read keys like
RESEND_API_KEYorSTRIPE_SECRET_KEYfrom secrets. A missing one comes back empty, and the call to that service fails. Add it with the exact name the code uses: in Lovable, More → Settings → Secrets; in Bolt, database icon → Secrets; in Supabase, Edge Functions → Secrets. After you remix a Lovable project, only the names of your secrets are copied, so enter each value again. - A key the outside service rejects: wrong, expired, from test mode, or out of credit. The log shows that service's own error. Copy a fresh key from the service's dashboard into the secret.
- A crash in the code, often from data it didn't expect: the app sent a different body, or an outside service answered with something else. The log gives the error and the line, like this example from Supabase's docs:
TypeError: Cannot read properties of undefined (reading 'some_func')
at Object.handler (file:///var/tmp/sb-compile-edge-runtime/source/index.ts:15:26)
Here, line 15 of the function's index.ts is where it broke. Paste the whole log entry into Lovable or Bolt and ask it to fix that function.
4. 503, 504 or 546: the function couldn't start or finish
- 503 with
BOOT_ERRORandFunction failed to start (please check logs): the function didn't even start, usually because of a syntax error or an import that fails, like a package version that doesn't exist. Its log has a line withworker boot errorthat names the problem. Paste it into the chat. Where to find that line and the usual fixes: Edge Function 503 BOOT_ERROR "Function failed to start (please check logs)". A 503 withoutBOOT_ERRORcan also mean Supabase itself is having trouble: check status.supabase.com. - 504: the function didn't answer within 150 seconds. That's usually a slow call to an outside service, like a long AI generation, or a loop over many items. Ask for a time limit on the slow call, and split big jobs into smaller ones.
- 546 with
WORKER_RESOURCE_LIMIT: the function ran out of memory (256 MB) or CPU time (2 seconds of actual computing per request; waiting for other services doesn't count). The log saysMemory limit exceededorCPU Time exceeded. It's common when a function processes big files or images, or loads a whole table at once. Process smaller pieces at a time. Which limit it was, and why it fails only sometimes: Edge Function 546 "not having enough compute resources" (WORKER_RESOURCE_LIMIT).
5. "Failed to send a request to the Edge Function"
This message is different: your app never got an answer it could read, so there's no status code to match. In our test, the console showed why, with one of these two lines:
Access to fetch at '…/functions/v1/send-email' from origin '…' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Access to fetch at '…/functions/v1/send-email' from origin '…' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Both are CORS errors. Before a browser sends the real request, it asks the function for permission with an OPTIONS request, and it only lets your app read answers that carry the right CORS headers. The first line, the one with Response to preflight request in it, means the function doesn't answer that OPTIONS request. The second means it answered, often with an error, but without the headers, so the browser hid the answer from your app. The fix is the same for both: answer OPTIONS, and put the CORS headers on every response, errors included. Here's Supabase's example:
import { corsHeaders } from 'npm:@supabase/supabase-js@^2/cors'
export default {
fetch: async (req) => {
// Handle the CORS preflight request.
if (req.method === 'OPTIONS') {
return Response.json({ ok: true }, { headers: corsHeaders })
}
try {
const { name } = await req.json()
return Response.json({ message: `Hello ${name}!` }, { headers: corsHeaders })
} catch (error) {
const message = error instanceof Error ? error.message : String(error)
return Response.json({ error: message }, { status: 400, headers: corsHeaders })
}
},
}
If your function starts with Deno.serve(async (req) => { or serve(async (req) => { instead, the same lines go inside it. The other causes of this message:
- The function doesn't exist: the app and the function use different names, the function was never deployed, or the app points at a different Supabase project than the one with the function. Supabase's docs note that browsers report this 404 as a CORS error, so it looks like the cases above. The function's logs stay empty, since the request never reached it. Compare the name in the failing address with your list of functions. Every cause, tested: Edge Function 404 "Requested function was not found".
- The request never left the browser: no connection, or an extension like an ad blocker stopped it. Try a private window with extensions off.
Every other CORS line, like It does not have HTTP ok status or Request header field x-client-info is not allowed, and why a function can pass on your machine and fail once deployed: Supabase Edge Function "blocked by CORS policy".
If the message is Relay Error invoking the Edge Function instead, Supabase's docs describe it as a network problem between your app and Supabase, not a bug in your function. Try again, and check status.supabase.com.
Still stuck?
Write down three things: the function's name, the status code (or the CORS line from the console), and the error from the response or the logs. That's what anyone helping you will ask for first, and the log line often points straight to the fix. In Lovable, also check that the project isn't paused: edge functions don't run while it is.
Other Supabase problems? See Supabase fixes.