{"record":{"id":"7f52b04aa9d18dd3","repo":"badges/shields","slug":"wordpress-version-api-response-error-message","errorCode":null,"errorMessage":"WordPress version API response: ${error.message}","messagePattern":"WordPress version API response: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"services/wordpress/wordpress-version-color.js","lineNumber":26,"sourceCode":"    offers: Joi.array()\n      .items(\n        Joi.object()\n          .keys({\n            version: optionalDottedVersionNClausesWithOptionalSuffix,\n          })\n          .required(),\n      )\n      .required(),\n  })\n  .required()\n\nasync function getOfferedVersions() {\n  return getCachedResource({\n    url: 'https://api.wordpress.org/core/version-check/1.7/',\n    scraper: json => {\n      const { error, value } = schema.validate(json, { allowUnknown: true })\n      if (error) {\n        throw Error(`WordPress version API response: ${error.message}`)\n      }\n      return value.offers.map(v => v.version)\n    },\n  })\n}\n\nfunction toSemver(v) {\n  const parts = v.split('-')\n  if (parts.length > 2) {\n    return v\n  }\n  const version = parts[0]\n  const suffix = parts[1] ? parts[1] : ''\n  if (version.split('.').length === 2) {\n    return suffix !== '' ? `${version}.0-${suffix}` : `${version}.0`\n  } else {\n    return v\n  }","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/wordpress/wordpress-version-color.js#L8-L44","documentation":"getOfferedVersions() in services/wordpress-version-color.js fetches WordPress core version data from api.wordpress.org and validates the JSON with a schema inside the scraper. When the API response shape does not match (missing offers, non-string versions, unexpected structure), it throws this Error with the schema validation message. It wraps upstream API contract changes into a descriptive error.","triggerScenarios":"The WordPress version-check/1.7 endpoint returns JSON failing schema.validate — e.g. the response omits the 'offers' array, offers lack a 'version' field, or a non-JSON error page is somehow parsed.","commonSituations":"WordPress changes its core/version-check/1.7 API format; the API returns a maintenance or error payload; a proxy/firewall returns an HTML error page instead of JSON; transient network failures yield truncated responses.","solutions":["Inspect error.message to see which schema constraint failed and compare with the current API response shape","Add/adjust the schema (with allowUnknown) to tolerate new optional fields or the new response structure","Add retry/backoff via the caching layer for transient failures, and catch the error upstream to serve a cached or fallback version list"],"exampleFix":"// before\nconst { error, value } = schema.validate(json, { allowUnknown: true })\nif (error) {\n  throw Error(`WordPress version API response: ${error.message}`)\n}\nreturn value.offers.map(v => v.version)\n// after\nconst { error, value } = schema.validate(json, { allowUnknown: true })\nif (error) {\n  throw new InvalidResponse({ prettyMessage: `WordPress version API response: ${error.message}` })\n}\nreturn (value.offers || []).map(v => v.version)","handlingStrategy":"retry","validationCode":"if (!json || !Array.isArray(json.offers)) {\n  throw new Error('Unexpected WordPress version API payload: missing offers array')\n}","typeGuard":"function isValidWordPressVersionResponse(json) {\n  return typeof json === 'object' && json !== null &&\n    Array.isArray(json.offers) &&\n    json.offers.every(o => typeof o?.version === 'string')\n}","tryCatchPattern":"try {\n  return await getOfferedVersions()\n} catch (err) {\n  if (err.message.startsWith('WordPress version API response:')) {\n    // transient/contract issue: use cached or empty fallback\n    return cachedVersions ?? []\n  }\n  throw err\n}","preventionTips":["Wrap the fetch in retry with exponential backoff for transient failures","Serve stale cached versions on validation failure","Keep the schema tolerant of added fields (allowUnknown: true)","Watch the WordPress API changelog for breaking response changes"],"tags":["schema-validation","external-api","wordpress"],"backgroundTag":"schema-validation-failed","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}