{"record":{"id":"67eff14619d53185","repo":"santifer/career-ops","slug":"themuse-unexpected-api-response-on-page-0-expec","errorCode":null,"errorMessage":"themuse: unexpected API response on page 0 — expected { results: [...] }, got keys: [${first ? Object.keys(first).join(', ') : 'null'}]","messagePattern":"themuse: unexpected API response on page 0 — expected (.+?), got keys: \\[(.+?)\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/themuse.mjs","lineNumber":147,"sourceCode":"export default {\n  id: 'themuse',\n\n  async fetch(_entry, ctx) {\n    assertMuseUrl(FEED_BASE);\n\n    // Page 0 is fetched outside the tolerant loop below and its failure is\n    // NOT caught: a completely dead board must throw, not return []. A\n    // caught page-0 failure would return an empty array indistinguishable\n    // from a healthy \"0 jobs today\" result -- scan.mjs's consecutive-failure\n    // detector resets its streak on any non-throwing fetch, so a themuse\n    // outage would silently reset the very detector meant to catch it.\n    // Mirrors workday.mjs, which fetches its first page outside the\n    // retry-tolerant loop (`page = 1` start) for the same reason.\n    const firstUrl = `${FEED_BASE}?page=0`;\n    // redirect:'error' prevents SSRF via server-side redirects\n    const first = await fetchPageWithRetry(ctx, firstUrl, { redirect: 'error' });\n    if (!first || !Array.isArray(first.results)) {\n      throw new Error(\n        `themuse: unexpected API response on page 0 — expected { results: [...] }, got keys: [${first ? Object.keys(first).join(', ') : 'null'}]`,\n      );\n    }\n    const allResults = [...first.results];\n    const pageCount = Number.isInteger(first.page_count) && first.page_count > 1\n      ? Math.min(first.page_count, MAX_PAGES)\n      : 1;\n\n    // Pages 1+ stay tolerant: a page that exhausts retries, OR comes back\n    // with an unexpected shape (a successful fetch, no retry involved --\n    // caught here so it lands in the same truncation path instead of\n    // escaping uncaught and discarding allResults), truncates with a warning\n    // and returns whatever was already gathered instead of discarding it.\n    for (let page = 1; page < pageCount; page++) {\n      await sleep(INTER_PAGE_DELAY_MS, ctx);\n      const url = `${FEED_BASE}?page=${page}`;\n      let json;\n      try {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/themuse.mjs#L129-L165","documentation":"The themuse provider fetches page 0 outside the retry-tolerant loop and treats it as the schema probe: the response must be an object with a results array, from which page_count is read. Anything else (null body, an error object, HTML-as-text) throws immediately, because without a valid first page the provider cannot determine pagination or any results at all.","triggerScenarios":"fetch() requests `${FEED_BASE}?page=0` via fetchPageWithRetry with redirect:'error'; the returned JSON is falsy or first.results is not an Array — API outage, error payload, Cloudflare challenge with 200, or a Muse API schema change.","commonSituations":"The Muse API is down or returning a maintenance payload; an HTML bot-challenge page is served with status 200; the public API version was bumped and { results: [...] } became { data: [...] }; an invalid API key/plan producing an error JSON body.","solutions":["Re-run the scan — first-page failures here are often transient upstream problems.","Open the feed URL in a browser or curl it to inspect the actual body (the error lists the top-level keys you got instead).","Check the Muse developer status/changelog for API schema or version changes and update the provider if the envelope changed.","Verify any API key/plan requirements for the public job feed and that your rate isn't being throttled into error bodies."],"exampleFix":"// before (provider expects old envelope)\nif (!first || !Array.isArray(first.results)) throw new Error(...);\n// after — if Muse moved to a data envelope, adapt the probe\nconst results = first?.results ?? first?.data;\nif (!results || !Array.isArray(results)) throw new Error('themuse: no results array in response');","handlingStrategy":"try-catch","validationCode":"function isMuseFirstPage(json) {\n  return !!json && typeof json === 'object' && Array.isArray(json.results);\n}\n// probe before depending on pagination:\n// const probe = await fetch(`${FEED_BASE}?page=0`).then(r => r.json());\n// if (!isMuseFirstPage(probe)) the API is down or changed — don't run the scan","typeGuard":"const hasResults = (v) =>\n  v !== null && typeof v === 'object' && Array.isArray(v.results);","tryCatchPattern":"try {\n  return await themuseProvider.fetch(entry, ctx);\n} catch (err) {\n  if (String(err.message).includes('unexpected API response on page 0')) {\n    console.error(`themuse feed unavailable or schema changed for ${entry.name}: ${err.message}`);\n    return { jobs: [], degraded: true }; // skip this scan round\n  }\n  throw err;\n}","preventionTips":["Health-check the Muse feed URL with curl before scheduled scans","Subscribe to / watch Muse developer status for schema or version announcements","Keep a fixture of a valid page-0 response and validate it in CI against the provider's expectations","Treat recurring page-0 failures as an upstream outage signal, not a config bug"],"tags":["api","schema","themuse","unexpected-response"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}