{"record":{"id":"9410874c859510a0","repo":"santifer/career-ops","slug":"yourator-unexpected-api-response-on-page-page","errorCode":null,"errorMessage":"yourator: unexpected API response on page ${page} — expected { payload: { jobs: [...] } }, got keys: [${json ? Object.keys(json).join(', ') : 'null'}]","messagePattern":"yourator: unexpected API response on page (.+?) — expected (.+?) \\}, got keys: \\[(.+?)\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/yourator.mjs","lineNumber":189,"sourceCode":"/** @type {Provider} */\nexport default {\n  id: 'yourator',\n\n  async fetch(entry, ctx) {\n    assertYouratorUrl(FEED_BASE);\n    // ctx.maxPages is verify-portals.mjs's \"first page only\" health probe — it\n    // always wins over the entry's own bound.\n    const maxPages = Math.min(resolveMaxPages(entry), ctx?.maxPages ?? Number.POSITIVE_INFINITY);\n    const fallbackCompany = entry?.name;\n    const out = [];\n\n    for (let page = 1; page <= maxPages; page++) {\n      const url = `${FEED_BASE}?page=${page}`;\n      // redirect:'error' prevents SSRF via server-side redirects\n      const json = await ctx.fetchJson(url, { redirect: 'error' });\n      const jobs = json?.payload?.jobs;\n      if (!Array.isArray(jobs)) {\n        throw new Error(\n          `yourator: unexpected API response on page ${page} — expected { payload: { jobs: [...] } }, got keys: [${json ? Object.keys(json).join(', ') : 'null'}]`,\n        );\n      }\n      for (const j of jobs) {\n        const normalized = normalizeYouratorJob(j, fallbackCompany);\n        if (normalized) out.push(normalized);\n      }\n      // `hasMore` is the API's own end-of-board signal and the only stop\n      // condition: past the last page it answers with an empty array and\n      // hasMore:false. A short-page heuristic is deliberately NOT used — it\n      // cannot help (maxPages already bounds a runaway walk) and a single short\n      // intermediate page would silently truncate the board.\n      if (json.payload.hasMore !== true) break;\n      if (page < maxPages) {\n        await (ctx.sleep ? ctx.sleep(PAGE_DELAY_MS) : new Promise(r => setTimeout(r, PAGE_DELAY_MS)));\n      }\n    }\n    return out;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/yourator.mjs#L171-L207","documentation":"The yourator provider fetches each results page and requires the JSON body to have the shape { payload: { jobs: [...] } }. If json is null, payload is missing, or payload.jobs is not an array, fetch throws this error naming the page number and the top-level keys actually received. It guards against API redesigns, empty/blocked responses, and HTML error bodies masquerading as parsed JSON.","triggerScenarios":"Yourator changes its response envelope (renames payload or jobs), the page exceeds the available results and returns an empty object, a CDN/WAF returns an error JSON, or the fetch silently got a non-API response.","commonSituations":"Yourator ships an API v2 renaming fields; requesting page N beyond the last page for a company with few jobs; anti-bot challenge on a datacenter IP; transient API outage returning an error envelope.","solutions":["Print the failing page's raw body to see the actual keys returned (the error already lists top-level keys)","If it happens only past the last page, treat a missing jobs array on an empty page as end-of-results instead of an error (guard with break on empty payload)","Check whether Yourator renamed payload/jobs and update the destructuring in fetch/normalizeYouratorJob accordingly","Retry once on transient failures; if a WAF blocks you, add proper headers or use a residential network"],"exampleFix":"// before\nconst jobs = json?.payload?.jobs;\nif (!Array.isArray(jobs)) throw new Error(...);\n// after: tolerate empty final page\nconst jobs = json?.payload?.jobs;\nif (!Array.isArray(jobs)) {\n  if (page > 1 && json && Object.keys(json).length === 0) break;\n  throw new Error(`yourator: unexpected API response on page ${page}`);\n}","handlingStrategy":"type-guard","validationCode":"// cheap preflight on page 1 before looping pages\nconst first = await ctx.fetchJson(`${FEED_BASE}?page=1`, { redirect: 'error' });\nif (!first?.payload || !Array.isArray(first.payload.jobs)) {\n  throw new Error(`yourator envelope changed: keys=${Object.keys(first ?? {}).join(',')}`);\n}","typeGuard":"function isYouratorJobsPage(json) {\n  return !!json && typeof json === 'object' &&\n    typeof json.payload === 'object' && json.payload !== null &&\n    Array.isArray(json.payload.jobs);\n}","tryCatchPattern":"try {\n  await scanYourator(entry);\n} catch (e) {\n  if (e.message.startsWith('yourator: unexpected API response')) {\n    console.warn('Check the raw page body — envelope rename, empty last page, or WAF block.');\n  } else throw e;\n}","preventionTips":["Stop paginating when a page returns an empty/shapeless payload instead of erroring","Record a fixture of a real page response and test normalizeYouratorJob against it","Use redirect:'error' and realistic headers to avoid WAF/redirect interference","Watch for Yourator API version announcements that rename payload/jobs"],"tags":["network","yourator","response-shape","scraper"],"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"}