502 Bad Gateway / NO_RESPONSE_FROM_FUNCTION on Vercel
On this page
Short answer
Your function ran and ended without sending a response back. Vercel's first troubleshooting step is to check that the function has "the necessary return statements to generate a response." Open the runtime logs in Live mode, repeat the failing request, and find the code path that ends without returning a Response.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.
The exact error you'll see
Vercel's error reference lists the code with status 502:
502
NO_RESPONSE_FROM_FUNCTION
Bad Gateway
Source: https:/
The full list of Vercel error codes, with their status codes, is at vercel.com/docs/errors (opens in a new tab).
Applies to
- Vercel Functions: Next.js route handlers and API routes, and files in the
api/folder - Apps built with v0 or Cursor and deployed to Vercel
- Settings involved: the Logs section of your project, and the deployment that served the request
Why it happens
Vercel says the error "occurs when a function invocation completes without returning a response." It lists three possible causes:
- "A global uncaught exception." An error nothing catches stops the function before it responds.
- "A global unhandled rejection." A promise fails and nothing catches it.
- "A deployment that introduced incorrect syntax." A recent deploy broke the code.
Vercel adds that it can also happen "if it fails to generate a response within the allowed execution time." Slow outside services are worth checking too: Vercel's steps say to make sure any external services or APIs your function relies on "are responding in a timely manner."
If the logs show a crash with code 500 instead, see Vercel 500 FUNCTION_INVOCATION_FAILED. If they show a 504, see Vercel FUNCTION_INVOCATION_TIMEOUT.
How to fix it, step by step
- Open your project and select Logs in the sidebar. Turn on Live mode. Vercel's steps say to keep the logs tab open "while reproducing the error."
- Repeat the request that failed. Filter by Request Path and Status Code to find it, then read its log lines to see where the function stopped.
- Check every branch of the handler. Each one, including early exits and error branches, must end by returning a response. A Next.js route handler returns a
Response, as in this example from the Next.js reference:
export async function GET() {
return Response.json({ message: 'Hello World' })
}
- For a function in the
api/folder, Vercel's Node.js docs show the same pattern with a named export per HTTP method:
export function GET(request: Request) {
return new Response('Hello from Vercel!');
}
If your function uses the older Node.js style with a response object, Vercel documents response.send(body) and response.json(obj) for sending the reply.
- Catch errors in the work that can fail, such as database and API calls, and return an error response with a clear status. That covers the first two causes Vercel lists: uncaught exceptions and unhandled rejections.
- Redeploy, then repeat the exact request that failed.
What the docs don't spell out
- Live mode is the way to watch it happen. The
vercel logsCLI "returns a bounded set of results and doesn't stream." Vercel says to use Live mode in the dashboard to follow logs in real time. (Runtime logs (opens in a new tab)) - Errors may not stick around. Vercel's troubleshooting steps suggest creating a Log Drain "to persist errors from Vercel functions" if you don't have one. (NO_RESPONSE_FROM_FUNCTION (opens in a new tab))
- Streaming still counts against the time limit. Vercel's maximum duration includes "time spent processing the request and sending the response, including streamed responses." (Function limits (opens in a new tab))
How to check it worked
- The request that failed now returns the status and body you expect, not 502.
- In Logs, filtered to that path, no new 502 entries appear after the redeploy.
- The deployment you're testing was created after your fix.
Sources
- https:/
/ : definition, 502 status, three causes, troubleshooting steps, Log Drain advice, external servicesvercel. com/ docs/ errors/ NO_ RESPONSE_ FROM_ FUNCTION (opens in a new tab) - https:/
/ : list of Vercel error codes and status codesvercel. com/ docs/ errors (opens in a new tab) - https:/
/ : Logs in the sidebar, Live mode, Request Path and Status Code filters, CLI doesn't streamvercel. com/ docs/ logs/ runtime (opens in a new tab) - https:/
/ : route handlernextjs. org/ docs/ app/ api- reference/ file- conventions/ route (opens in a new tab) Response.jsonexample - https:/
/ : namedvercel. com/ docs/ functions/ runtimes/ node- js (opens in a new tab) GETexport example,response.sendandresponse.json - https:/
/ : maximum duration includes streamed responsesvercel. com/ docs/ functions/ limitations (opens in a new tab)
Related fixes
Tool to consider: Vercel.
Find a fix pack
Checklists and prompts for Supabase security, Stripe payments and deploys. Each pack is $24, or $49 for all three.