{"record":{"id":"56c216c2775ada38","repo":"badges/shields","slug":"maximum-response-size-exceeded","errorCode":null,"errorMessage":"Maximum response size exceeded","messagePattern":"Maximum response size exceeded","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"core/base-service/got.js","lineNumber":21,"sourceCode":"import {\n  fetchLimitBytes as fetchLimitBytesDefault,\n  getUserAgent,\n} from './got-config.js'\n\nconst userAgent = getUserAgent()\n\nasync function sendRequest(gotWrapper, url, options = {}, systemErrors = {}) {\n  const gotOptions = Object.assign({}, options)\n  gotOptions.throwHttpErrors = false\n  gotOptions.retry = { limit: 0 }\n  gotOptions.headers = gotOptions.headers || {}\n  gotOptions.headers['User-Agent'] = userAgent\n  try {\n    const resp = await gotWrapper(url, gotOptions)\n    return { res: resp, buffer: resp.body }\n  } catch (err) {\n    if (err.code === 'ERR_ABORTED') {\n      throw new InvalidResponse({\n        underlyingError: new Error('Maximum response size exceeded'),\n      })\n    }\n    if (err.code in systemErrors) {\n      throw new Inaccessible({\n        ...systemErrors[err.code],\n        underlyingError: err,\n      })\n    }\n    throw new Inaccessible({ underlyingError: err })\n  }\n}\n\nfunction _fetchFactory(fetchLimitBytes = fetchLimitBytesDefault) {\n  const gotWithLimit = got.extend({\n    handlers: [\n      (options, next) => {\n        const abortController = new AbortController()","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/core/base-service/got.js#L3-L39","documentation":"sendRequest wraps got; when got aborts the transfer because the response exceeded the configured maximum body size, the request fails with code 'ERR_ABORTED', and sendRequest converts that into InvalidResponse with underlyingError 'Maximum response size exceeded'. This guards against accidentally downloading huge bodies from upstream endpoints.","triggerScenarios":"The requested endpoint returns a body larger than the maxResponseSize configured for got (e.g. a huge JSON/XML export, a large file mistakenly pointed at, or a proxy ignoring size limits), causing got to abort with ERR_ABORTED.","commonSituations":"Querying an API without filters so it returns thousands of records; endpoints serving big reports/logs; misconfigured URL hitting a binary/download route instead of a metadata API; intentionally larger upstream payloads after an upstream upgrade.","solutions":["Narrow the request so the response is small (add filters, query params, pagination, or point at a lighter endpoint)","Check that the URL targets the metadata/API route, not a large download or raw artifact","If larger responses are genuinely required, raise the service's max response size option where supported","Cache or pre-filter server-side if you control the upstream"],"exampleFix":"// before\nconst { buffer } = await sendRequest('https://registry.example.org/api/v1/all') // full registry dump -> exceeds max size\n// after\nconst { buffer } = await sendRequest(`https://registry.example.org/api/v1/package/${encodeURIComponent(name)}`)","handlingStrategy":"try-catch","validationCode":"// server-side pre-check to keep responses small\nconst head = await fetch(url, { method: 'HEAD' })\nconst size = Number(head.headers.get('content-length') || 0)\nif (size > 2 * 1024 * 1024) throw new Error(`response of ${size} bytes exceeds max size; narrow the query`)","typeGuard":null,"tryCatchPattern":"try {\n  const { buffer } = await sendRequest(url)\n} catch (err) {\n  if (err.underlyingError?.message === 'Maximum response size exceeded') {\n    // narrow query params / paginate / use a lighter endpoint, then retry\n  } else throw err\n}","preventionTips":["Always filter/paginate API queries so bodies stay small","Point at metadata endpoints, not file/download routes","HEAD-check content-length for endpoints with variable payload sizes","Know your service's max response size and design queries to fit well under it"],"tags":["network","response-size","got","invalid-response"],"backgroundTag":"max-response-size-exceeded","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}