badges/shields · error · InvalidResponse

Maximum response size exceeded

Error message

Maximum response size exceeded

What it means

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.

Solutions

  1. Narrow the request so the response is small (add filters, query params, pagination, or point at a lighter endpoint)
  2. Check that the URL targets the metadata/API route, not a large download or raw artifact
  3. If larger responses are genuinely required, raise the service's max response size option where supported
  4. Cache or pre-filter server-side if you control the upstream

Example fix

// before
const { buffer } = await sendRequest('https://registry.example.org/api/v1/all') // full registry dump -> exceeds max size
// after
const { buffer } = await sendRequest(`https://registry.example.org/api/v1/package/${encodeURIComponent(name)}`)
Defensive patterns

Strategy: try-catch

Validate before calling

// server-side pre-check to keep responses small
const head = await fetch(url, { method: 'HEAD' })
const size = Number(head.headers.get('content-length') || 0)
if (size > 2 * 1024 * 1024) throw new Error(`response of ${size} bytes exceeds max size; narrow the query`)

Try / catch

try {
  const { buffer } = await sendRequest(url)
} catch (err) {
  if (err.underlyingError?.message === 'Maximum response size exceeded') {
    // narrow query params / paginate / use a lighter endpoint, then retry
  } else throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/56c216c2775ada38. Report an issue: GitHub.

Appendix: source

Thrown at core/base-service/got.js:21

import {
  fetchLimitBytes as fetchLimitBytesDefault,
  getUserAgent,
} from './got-config.js'

const userAgent = getUserAgent()

async function sendRequest(gotWrapper, url, options = {}, systemErrors = {}) {
  const gotOptions = Object.assign({}, options)
  gotOptions.throwHttpErrors = false
  gotOptions.retry = { limit: 0 }
  gotOptions.headers = gotOptions.headers || {}
  gotOptions.headers['User-Agent'] = userAgent
  try {
    const resp = await gotWrapper(url, gotOptions)
    return { res: resp, buffer: resp.body }
  } catch (err) {
    if (err.code === 'ERR_ABORTED') {
      throw new InvalidResponse({
        underlyingError: new Error('Maximum response size exceeded'),
      })
    }
    if (err.code in systemErrors) {
      throw new Inaccessible({
        ...systemErrors[err.code],
        underlyingError: err,
      })
    }
    throw new Inaccessible({ underlyingError: err })
  }
}

function _fetchFactory(fetchLimitBytes = fetchLimitBytesDefault) {
  const gotWithLimit = got.extend({
    handlers: [
      (options, next) => {
        const abortController = new AbortController()

View on GitHub (pinned to 766fd8bc89)