{"record":{"id":"39ca51b23207440d","repo":"badges/shields","slug":"invalid-json-response","errorCode":null,"errorMessage":"invalid json response","messagePattern":"invalid json response","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"services/npm/npm-base.js","lineNumber":144,"sourceCode":"      url,\n      httpErrors: { 404: 'package not found' },\n    })\n\n    let packageData\n    if (scope === undefined && tag === undefined) {\n      packageData = json\n    } else {\n      const registryTag = tag || 'latest'\n      let latestVersion\n      try {\n        latestVersion = json['dist-tags'][registryTag]\n      } catch (e) {\n        throw new NotFound({ prettyMessage: 'tag not found' })\n      }\n      try {\n        packageData = json.versions[latestVersion]\n      } catch (e) {\n        throw new InvalidResponse({ prettyMessage: 'invalid json response' })\n      }\n    }\n\n    return this.constructor._validate(packageData, packageDataSchema)\n  }\n\n  async fetch({\n    registryUrl,\n    scope,\n    packageName,\n    schema,\n    abbreviated = false,\n  }) {\n    registryUrl = registryUrl || this.constructor.defaultRegistryUrl\n    let url\n\n    if (scope === undefined) {\n      url = `${registryUrl}/${packageName}`","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/npm/npm-base.js#L126-L162","documentation":"Thrown when the resolved latestVersion does not map to an entry in json.versions, leaving packageData undefined so the subsequent schema validation path is invalid. The service wraps the versions lookup in try/catch and converts the failure into InvalidResponse 'invalid json response'. In practice this means the registry metadata is inconsistent: a dist-tag points at a version that is not present in the versions map.","triggerScenarios":"Registry JSON where dist-tags references a version missing from json.versions (truncated/corrupted metadata); a proxy/mirror returning partial documents; json.versions absent entirely so the property access path breaks.","commonSituations":"Using a stale or misbehaving npm mirror (e.g. corporate proxy) whose metadata cache is inconsistent; third-party registries with non-standard metadata; race during package publish/unpublish where tags and versions diverge.","solutions":["Retry against the official registry (registry.npmjs.org) to bypass a stale mirror/proxy cache","Run `npm view <pkg>` and compare dist-tags vs versions; republish or `npm dist-tag add` to fix a dangling tag if you own the package","Purge the mirror/proxy cache for the package metadata","If servicing code, add an explicit check `if (!packageData) throw new InvalidResponse(...)` instead of relying on try/catch"],"exampleFix":"// before\ntry { packageData = json.versions[latestVersion] } catch (e) { throw new InvalidResponse(...) }\n// after\npackageData = json.versions && latestVersion ? json.versions[latestVersion] : undefined\nif (!packageData) throw new InvalidResponse({ prettyMessage: 'invalid json response' })","handlingStrategy":"try-catch","validationCode":"const meta = await fetch(`${registry}/${pkg}`).then(r => r.json())\nconst latest = meta && meta['dist-tags'] && meta['dist-tags'].latest\nif (!latest || !meta.versions || !(latest in meta.versions)) {\n  throw new Error(`registry metadata inconsistent: tag '${latest}' missing from versions`)\n}","typeGuard":"function hasConsistentMetadata(json) {\n  const v = json && json['dist-tags'] && json['dist-tags'].latest\n  return Boolean(v && json.versions && json.versions[v])\n}","tryCatchPattern":"try {\n  return await npmBadge({ pkg })\n} catch (e) {\n  if (e instanceof InvalidResponse && e.message === 'invalid json response') {\n    // likely a stale mirror; retry official registry\n    return npmBadge({ pkg, registry: 'https://registry.npmjs.org' })\n  }\n  throw e\n}","preventionTips":["Point badges at the official registry or a mirror you know refreshes promptly","Retry transient metadata glitches once before surfacing them","If you own the package, repair dangling dist-tags with `npm dist-tag add`","Cache-bust (add a query param) when you suspect a stale proxy cache"],"tags":["npm","invalid-response","registry","metadata"],"backgroundTag":"invalid-json-response","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}