{"record":{"id":"49772bacf2b10e07","repo":"vercel/next.js","slug":"proxy-request-aborted-request-method-request","errorCode":null,"errorMessage":"Proxy request aborted [${request.method} ${request.url}]","messagePattern":"Proxy request aborted \\[(.+?) (.+?)\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/experimental/testmode/fetch.ts","lineNumber":125,"sourceCode":"      'next-test-internal': '1',\n    },\n    next: {\n      // @ts-ignore\n      internal: true,\n    },\n  })\n  if (!resp.ok) {\n    throw new Error(`Proxy request failed: ${resp.status}`)\n  }\n\n  const proxyResponse = (await resp.json()) as ProxyResponse\n  const { api } = proxyResponse\n  switch (api) {\n    case 'continue':\n      return originalFetch(request)\n    case 'abort':\n    case 'unhandled':\n      throw new Error(\n        `Proxy request aborted [${request.method} ${request.url}]`\n      )\n    case 'fetch':\n      return buildResponse(proxyResponse)\n    default:\n      return api satisfies never\n  }\n}\n\nexport function interceptFetch(originalFetch: Fetch) {\n  global.fetch = function testFetch(\n    input: FetchInputArg,\n    init?: FetchInitArg\n  ): Promise<Response> {\n    // Passthrough internal requests.\n    // @ts-ignore\n    if (init?.next?.internal) {\n      return originalFetch(input, init)","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/experimental/testmode/fetch.ts#L107-L143","documentation":"Thrown by the experimental testmode fetch interceptor when the test proxy responds with api 'abort' or 'unhandled' for a fetch. 'unhandled' means no registered mock matched the request URL/method; 'abort' is an explicit signal from the test to terminate the request. The message includes the original method and URL to help identify which fetch was unmocked.","triggerScenarios":"A server-side fetch() executes during a testmode test, the proxy receives it, but no httpMockHandler matches (or the handler returned 'unhandled'), so the proxy tells Next.js to abort. Triggered per-fetch in app-router or pages-router server code under testmode.","commonSituations":"Forgetting to mock a fetch that a deep dependency performs (analytics, auth lookup, telemetry); URL pattern mismatch between mock and actual call (trailing slash, query, absolute vs relative); or a mock handler timing out and the test aborting. Also when the test ends before all in-flight fetches resolve.","solutions":["Register an httpMockHandler (or use mocked async handler) that matches the exact URL/method of the failing fetch shown in the message.","Loosen the mock matcher (wildcards, regex, ignore query params) so transient differences don't cause an unhandled result.","Use `api: 'continue'` (passthrough) in the handler for fetches you intentionally want to hit the network during tests.","Audit nested dependencies for surprise fetches and either mock or stub them at the module boundary."],"exampleFix":"// before — no mock for /api/user\n// fetch('/api/user') in server component -> abort\n// after — register a matching mock\nconst handlers = [\n  {\n    url: '*/api/user',\n    method: 'GET',\n    handler: async () => Response.json({ id: 1, name: 'ada' }),\n  },\n]","handlingStrategy":"validation","validationCode":"// Register a catch-all mock that returns 'continue' so unmocked fetches passthrough\nconst catchAll = { url: '*', handler: async () => ({ api: 'continue' }) }\n// or assert all expected fetches are mocked before the test runs","typeGuard":null,"tryCatchPattern":"try {\n  await runServerAction()\n} catch (e) {\n  if (/Proxy request aborted/.test(e.message)) {\n    console.error('Unmocked fetch detected:', e.message)\n    // register the missing mock and retry once\n  }\n  throw e\n}","preventionTips":["Register mocks for every fetch the code path performs, including deep dependencies.","Use a catch-all mock with `api: 'continue'` during development to avoid hard aborts.","Match URLs loosely (wildcards, ignore query) to reduce spurious unhandled results.","Audit nested deps for surprise network calls."],"tags":["testmode","experimental","mocking","fetch","testing"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}