Skip to content

Supabase Edge Functions errorSupabase: “Edge Function returned a non-2xx status code”

Your app calls supabase.functions.invoke() and gets back Edge Function returned a non-2xx status code, with no hint of what went wrong. Supabase documents this case as a FunctionsHttpError: your function ran but returned a 4xx or 5xx, and its own message is in the response. Here’s how to read it, in Supabase’s words, or hand it over at a fixed price.

Short answer

Your function ran but returned an error status (4xx or 5xx). In supabase-js that is a FunctionsHttpError, and the function’s own error message is in error.context: read it with await error.context.json(). Then check the function’s logs in the Logs tab of the Supabase dashboard, fix what the function reports, and have it return a clear status code and message.

How to find the real error

  1. 01

    The real error is in error.context

    “FunctionsHttpError: Your function executed but returned an error (4xx/5xx status)” Supabase, Edge Functions: Error handling

    Check which kind of error you got, and for a FunctionsHttpError, read the body the function sent back. This is Supabase’s example:

    import { FunctionsFetchError, FunctionsHttpError, FunctionsRelayError } from '@supabase/supabase-js'
    
    const { data, error } = await supabase.functions.invoke('hello', {
      headers: { 'my-custom-header': 'my-custom-header-value' },
      body: { foo: 'bar' },
    })
    
    if (error instanceof FunctionsHttpError) {
      const errorMessage = await error.context.json()
      console.log('Function returned an error', errorMessage)
    } else if (error instanceof FunctionsRelayError) {
      console.log('Relay error:', error.message)
    } else if (error instanceof FunctionsFetchError) {
      console.log('Fetch error:', error.message)
    }
  2. 02

    The function’s logs say what failed

    “You can see the production error logs in the Logs tab of your Supabase Dashboard.” Supabase, Edge Functions: Error handling

    Open the function in the dashboard and read its logs around the time of the failed call. Errors the function logs with console.error appear there; if it logs nothing, add logging around the step that fails.

  3. 03

    Every problem comes back as a 500

    “Return 400 for bad user input, 404 when something doesn't exist, 500 for server errors, etc.” Supabase, Edge Functions: Error handling

    If the function returns 500 for everything, the app can’t tell a bad form value from a crash. Return the right status with a JSON body that carries a message, so the app can show people something useful.

  4. 04

    A relay or fetch error is a different problem

    “FunctionsFetchError: Function couldn't be reached at all” Supabase, Edge Functions: Error handling

    If the error is a FunctionsRelayError or FunctionsFetchError instead, the function didn’t answer with its own error. We check the function name, that it is deployed, and the network before touching the function’s code.

Checked against the vendor’s docs on : Supabase docs: Edge Functions error handling.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Supabase Edge Function CORS error · Supabase Edge Function timeout · Lovable Edge Function secret missing · Supabase public storage bucket

Questions

More on this error

Is this a CORS problem?

Not by itself: a non-2xx status means the function answered with an error. If the browser console also shows a CORS error, see the Edge Function CORS fix linked below.

What do you need to fix it?

The function’s code and access to the Supabase project, or the app it belongs to. We read the logs and the error body, fix the function, and send the change as a pull request.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.