Supabase Edge Function Returns 500 or WORKER_ERROR? Find the Cause and Fix It

Updated 19 Oct 2026

Check your app now: free 30-second health check

Paste your live URL. We'll show what visitors and Google actually see. No signup.

Passive check only. We never submit forms or log in.

Your site calls a Supabase Edge Function to create a checkout, send an email, talk to an AI model or write to the database, and the call fails with 500. The browser console shows one of these:

  • Internal Server Error
  • FunctionsHttpError: Edge Function returned a non-2xx status code
  • a response header sb-error-code of WORKER_ERROR, EDGE_FUNCTION_ERROR, BOOT_ERROR or IDLE_TIMEOUT
  • an empty body, or a JSON body your own code wrote with status: 500

Visitors just see a button that does nothing, a spinner that never stops or a generic "Something went wrong". Because you often test while signed in with a full request body, it can work for you and fail for everyone else.

Edge Function 500s are common on Lovable, Bolt, v0 and Cursor builds: the builder writes the function for you, then a missing secret, a bad JSON.parse, an uncaught throw or a slow third-party call turns a working flow into a silent failure. The fix starts with telling who produced the 500.

Step 1: who sent the 500?

A 500 from an Edge Function comes from either:

  1. The platform / runtime, after your code threw an uncaught exception, failed to boot, timed out or hit a resource limit. The body is often the plain text Internal Server Error, and the response may include an sb-error-code header.
  2. Your own function code, which ran and deliberately returned status: 500 (or passed on a 500 from another service it called). The body is whatever you wrote, or empty.

How to tell:

  • Open your live site in a private window, open DevTools (F12), go to Network, and trigger the action. Click the request to /functions/v1/<function-name> and read the Response tab and response headers (sb-error-code if present).
  • In the Supabase dashboard, open Edge Functions → your function → Logs (or Invocations). Uncaught exceptions and stack traces appear under Logs; request status codes appear under Invocations.
  • If the body is exactly Internal Server Error with no custom JSON, go straight to the JavaScript-failure path below. If the body is your own message (or empty) and the logs show your console.log lines, your code returned the 500 itself.

Read the error properly on the client too. supabase.functions.invoke returns a FunctionsHttpError whose useful part is on error.context (the raw Response). Log error.context.status, error.context.headers.get('sb-error-code') and await error.context.text() instead of only the generic "non-2xx" string.

Supabase's troubleshooting page also gives a SQL query that joins function_logs and function_edge_logs for recent 500s. If you're comfortable in the SQL editor, that is the quickest way to match stack traces to the function that failed.

Step 2: if the platform sent it (WORKER_ERROR, BOOT_ERROR, timeout)

Check the sb-error-code header and the Logs tab. The common codes for a 500-class failure are:

CodeWhat it meansWhere to look
WORKER_ERRORThe function booted, then threw an uncaught exception during the request (or outside the handler at load time in some setups)Logs: stack trace, often TypeError / ReferenceError
EDGE_FUNCTION_ERRORUnhandled error or a 5xx your code producedLogs + any status: 500 returns in your source
BOOT_ERRORThe function never started (syntax error, bad import, top-level throw)Logs + supabase functions serve locally
IDLE_TIMEOUTStarted, did work, but did not respond in timeSlow DB query, slow third-party fetch, infinite loop
WORKER_RESOURCE_LIMIT / WORKER_LIMITMemory or CPU quota exceededLogs name which limit; shrink payloads / concurrency

A. Uncaught exception (WORKER_ERROR / EDGE_FUNCTION_ERROR)

Typical causes on AI-built sites:

  • reading a property of undefined after await req.json() on an empty body, or after a failed database call
  • a typo or missing import (ReferenceError: … is not defined)
  • JSON.parse on an empty string
  • a missing Edge Function secret so an API client is constructed with undefined and later throws
  • an awaited fetch that rejects with no try/catch

Fix: open the stack trace, go to the file and line it names, and either guard the value or wrap the handler in try/catch (Step 4). Redeploy after the change.

B. BOOT_ERROR

The function never runs, so every call fails the same way. Common causes: a syntax error, an import that does not resolve in the Deno runtime, or a top-level await that throws before Deno.serve / the default export is ready.

Fix: run supabase functions serve <name> locally. The same boot failure usually appears in under a second with a readable message. Fix the import or syntax, redeploy, and wait a minute for regions to pick up the new bundle.

C. IDLE_TIMEOUT

The function started and then sat on a slow operation until the platform cut it off.

Fix:

  • add an AbortController (or equivalent timeout) around outbound fetch calls and return a clear 504/502 early
  • shorten database queries; move long work to a queue instead of doing it inside the request
  • check whether a third-party API (Stripe, Resend, an AI provider) is the slow hop, using that provider's own logs

D. Resource limits

If logs say memory or CPU was exceeded, shrink what you hold in memory (large file buffers, big JSON bodies), avoid unbounded concurrency, and split heavy work.

Step 3: if your own code returned 500

Search the function for status: 500 (and status: "500"). Trace the condition that hit it. Often the real failure is upstream:

  • a Stripe / Resend / OpenAI call returned 500 or an error object you forwarded
  • a Supabase client call failed and you mapped every failure to 500
  • a webhook handler returned 500 so the sender would retry, but the root cause is a bad signature or missing secret

Fix:

  1. Log a reason before every 500 return: console.error('Returning 500:', reason).
  2. Prefer a more precise status when you know the cause (400 for bad input, 401/403 for auth, 502 for upstream).
  3. Check Edge Functions → Secrets for missing or old keys. Secrets set only in a builder's UI do not always reach the live project.

Step 4: wrap the handler so the next failure explains itself

Supabase's own guidance is to catch errors in your logic. A minimal pattern:

const corsHeaders = {
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
}

Deno.serve(async (req) => {
  if (req.method === 'OPTIONS') {
    return new Response('ok', { headers: corsHeaders })
  }

  try {
    const body = await req.json().catch(() => null)
    if (!body?.invoiceId) {
      return new Response(JSON.stringify({ error: 'invoiceId is required' }), {
        headers: { ...corsHeaders, 'Content-Type': 'application/json' },
        status: 400,
      })
    }
    // … real work …
    return new Response(JSON.stringify({ ok: true }), {
      headers: { ...corsHeaders, 'Content-Type': 'application/json' },
      status: 200,
    })
  } catch (err) {
    console.error(err)
    return new Response(JSON.stringify({ error: String(err) }), {
      headers: { ...corsHeaders, 'Content-Type': 'application/json' },
      status: 500,
    })
  }
})

That does not remove the bug, but it turns a mystery Internal Server Error into a 500 with a message in the response and a stack line in Logs. Put the OPTIONS handler first: if any error runs before CORS headers are returned, the browser may report a CORS failure even when the real problem is a crash (see API calls blocked after deploy? Check your CORS origins).

A 500 that is really something else

  • 401 Invalid JWT / Missing authorization header. That is the platform JWT check (or your own auth return), not a worker crash. Use the Edge Function 401 Invalid JWT guide.
  • CORS error in the console with no useful status. Fix the crash or auth failure first, then make sure every response (including errors and OPTIONS) returns CORS headers. A missing OPTIONS handler can also log SyntaxError: Unexpected end of JSON input when the body is read on a preflight.
  • 404 / function not found. Redeploy; concurrent deploys can leave metadata pointing at a missing bundle. Not a 500.
  • Every request fails, not just functions. Check whether the project was paused (Site loads but data is gone? Your free backend may be paused).

Quick checklist

  1. Read the response body, sb-error-code, and the function Logs: platform crash or your own status: 500?
  2. Internal Server Error / WORKER_ERROR: open the stack trace; guard undefined / empty JSON; add try/catch.
  3. BOOT_ERROR: reproduce with supabase functions serve, fix imports/syntax, redeploy.
  4. IDLE_TIMEOUT: timeout outbound fetches; shorten DB work; check third-party latency.
  5. Your own 500: log the reason; check Secrets; stop blindly forwarding upstream 500s.
  6. Put CORS OPTIONS handling first so browsers don't hide the real error.
  7. Test again in a private window with a normal test user and a realistic request body.

These failures hide behind buttons, so a quick look at the homepage won't show them. The free 30-second health check shows which pages on your live site fail to load, which links are broken and what errors appear in the console. For ongoing coverage, FlowCanary offers Daily monitoring of your signup, login and checkout (in development; founding spots $19/month, price locked for life, full refund on request any time before it launches).

Further reading

FAQ

What does WORKER_ERROR mean on a Supabase Edge Function?

The function started, then threw an uncaught exception during the request. The stack trace in Edge Function Logs names the file and line.

Why do I only see "Edge Function returned a non-2xx status code"?

That is the Supabase JS client's generic wrapper. Read error.context.status and await error.context.text() (and sb-error-code) for the real reason.

Should I return 500 from my own catch block?

Yes when something unexpected failed — but log the error and prefer 400/401/502 when you know the cause. A bare platform Internal Server Error is harder to debug than a JSON body you control.

Why does it work in the dashboard test but fail from my site?

The dashboard sends a clean request. Your live site may send an empty body, a different secret set, or hit a code path (webhook, unsigned-in user) the dashboard test never runs.

Related guides

Run the free 30-second check

Back to the FlowCanary homepage

FlowCanary on SaaSHub