{"record":{"id":"49bec4804fc3093f","repo":"santifer/career-ops","slug":"4dayweek-unexpected-api-response-on-page-page","errorCode":null,"errorMessage":"4dayweek: unexpected API response on page ${page} — expected { jobs: [...] }, got keys: [${json ? Object.keys(json).join(', ') : 'null'}]","messagePattern":"4dayweek: unexpected API response on page (.+?) — expected (.+?), got keys: \\[(.+?)\\]","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"providers/4dayweek.mjs","lineNumber":145,"sourceCode":"\n/** @type {Provider} */\nexport default {\n  id: '4dayweek',\n\n  detect: detectFourDayEntry,\n\n  async fetch(entry, ctx) {\n    assertFourDayUrl(FEED_BASE);\n    const maxPages = resolveMaxPages(entry);\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      if (!json || !Array.isArray(json.jobs)) {\n        throw new Error(\n          `4dayweek: unexpected API response on page ${page} — expected { jobs: [...] }, got keys: [${json ? Object.keys(json).join(', ') : 'null'}]`,\n        );\n      }\n      for (const j of json.jobs) {\n        const normalized = normalize4dwJob(j, fallbackCompany);\n        if (normalized) out.push(normalized);\n      }\n      if (json.has_more === false) break; // last page per the API flag\n      if (json.jobs.length < PER_PAGE) break; // short page → last page\n    }\n    return out;\n  },\n};\n","sourceCodeStart":127,"sourceCodeEnd":159,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/providers/4dayweek.mjs#L127-L159","documentation":"Thrown by the 4dayweek provider's fetch when a page of its paginated feed does not return JSON with a `jobs` array. The provider validates every page's shape (json truthy and Array.isArray(json.jobs)) before normalizing, because a changed API contract, an HTML error page parsed as JSON, or an empty/odd response would otherwise silently produce zero results. The message includes the actual top-level keys (or 'null') to aid diagnosis.","triggerScenarios":"fetchJson on `${FEED_BASE}?page=${page}` returns null, a JSON object without a `jobs` key, or a `jobs` value that is not an array — e.g. the API moved/changed schema, an error payload like {error:'...'}, or a proxy returning JSON-RPC/HTML-as-JSON.","commonSituations":"The 4dayweek feed API changed its response shape; requesting a page beyond the last page; a captive portal or WAF returning JSON error bodies with 200 status; CDN serving an error object during an outage.","solutions":["Log/fetch the URL manually and inspect the actual JSON keys reported in the error to see what the API now returns.","Check whether the feed API moved or changed its schema and update the provider's parsing to match.","Reduce max_pages or stop paginating at the first empty page if the error occurs on a high page number beyond the feed's end.","If an intermediary (proxy/WAF) is rewriting responses, bypass or fix it so the real feed JSON reaches the provider."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const json = await res.json();\nif (!json || !Array.isArray(json.jobs)) {\n  throw new Error(`feed shape changed: keys=${Object.keys(json ?? {}).join(',')}`);\n}","typeGuard":"function isJobsPage(json) {\n  return typeof json === 'object' && json !== null && Array.isArray(json.jobs);\n}","tryCatchPattern":"try {\n  const jobs = await fetch4dayweekPage(page);\n} catch (e) {\n  if (String(e.message).includes('unexpected API response')) {\n    console.error('4dayweek feed schema may have changed; inspect the keys in the message');\n    return []; // or alert, per policy\n  } else throw e;\n}","preventionTips":["Validate response shape at the fetch boundary with a small guard function.","Watch for feed API schema changes after provider updates.","Stop paginating when a page returns an empty or malformed body instead of pushing past the last page.","Pin/monitor the feed endpoint so outages and WAF rewrites are noticed early."],"tags":["api","response-shape","pagination","provider"],"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"}