App Finishers

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:

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:

[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:

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

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:

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.