{"record":{"id":"0d9fc6f7a6803fd3","repo":"vercel/next.js","slug":"invalid-response-res-status","errorCode":null,"errorMessage":"Invalid response ${res.status}","messagePattern":"Invalid response (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/api-utils/node/api-resolver.ts","lineNumber":317,"sourceCode":"    }\n\n    if (context.trustHostHeader) {\n      const res = await fetch(`https://${req.headers.host}${urlPath}`, {\n        method: 'HEAD',\n        headers,\n      })\n      // we use the cache header to determine successful revalidate as\n      // a non-200 status code can be returned from a successful revalidate\n      // e.g. notFound: true returns 404 status code but is successful\n      const cacheHeader =\n        res.headers.get('x-vercel-cache') || res.headers.get('x-nextjs-cache')\n\n      if (\n        cacheHeader?.toUpperCase() !== 'REVALIDATED' &&\n        res.status !== 200 &&\n        !(res.status === 404 && opts.unstable_onlyGenerated)\n      ) {\n        throw new Error(`Invalid response ${res.status}`)\n      }\n    } else {\n      throw new Error(\n        `Invariant: missing internal router-server-methods this is an internal bug`\n      )\n    }\n  } catch (err: unknown) {\n    throw new Error(\n      `Failed to revalidate ${urlPath}: ${isError(err) ? err.message : err}`\n    )\n  }\n}\n\nexport async function apiResolver(\n  req: IncomingMessage,\n  res: ServerResponse,\n  query: any,\n  resolverModule: any,","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/api-utils/node/api-resolver.ts#L299-L335","documentation":"Thrown during on-demand revalidation on platforms that revalidate via a network HEAD request (trustHostHeader path) when the response's cache header does not indicate 'REVALIDATED', the status is not 200, and it's not an allowed 404-onlyGenerated case. This signals the revalidation request did not succeed as expected.","triggerScenarios":"In the trustHostHeader branch, fetch(`https://${host}${urlPath}`) returns a non-200 status whose x-vercel-cache/x-nextjs-cache is not 'REVALIDATED', and the unstable_onlyGenerated 404 exception does not apply. Causes: the origin returned 500/403/502, the revalidate secret was rejected, or the route doesn't exist.","commonSituations":"Incorrect PRERENDER_REVALIDATE_HEADER token; the target path returns an error; deploying without the internal router-server method (serverless + trustHostHeader) and the origin rejects the revalidation request; networking/DNS issues hitting the host.","solutions":["Verify the previewModeId / revalidate token matches between caller and the Next.js server.","Confirm the urlPath exists and returns 200 normally (check logs for the actual status printed).","Ensure the deployment supports internal revalidation or that the host header is trusted and reachable.","Retry transient 5xx from the origin; investigate persistent non-200s as config mismatches."],"exampleFix":"// before\nawait res.revalidate('/missing-route') // origin returns 404, not onlyGenerated\n// after\nawait res.revalidate('/existing-route')","handlingStrategy":"try-catch","validationCode":"// Verify the route returns 200 and the revalidate token is correct before calling res.revalidate\nasync function verifyRouteReachable(host: string, path: string, token: string) {\n  const r = await fetch(`https://${host}${path}`, { method: 'HEAD' })\n  if (r.status !== 200) throw new Error(`Route returned ${r.status} before revalidate`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await res.revalidate(path)\n} catch (err) {\n  if (/Invalid response \\d+/.test(err.message)) {\n    // log status, verify token, then surface a user-facing error\n  }\n}","preventionTips":["Ensure the revalidate token matches the server's previewModeId.","Confirm the target route returns 200 normally.","Use the internal router-server method where available to avoid network revalidation."],"tags":["api-routes","revalidation","cache","network","runtime"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}