santifer/career-ops · error · Error

4dayweek: unexpected API response on page

Error message

4dayweek: unexpected API response on page ${page} — expected { jobs: [...] }, got keys: [${json ? Object.keys(json).join(', ') : 'null'}]

What it means

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.

Solutions

  1. Log/fetch the URL manually and inspect the actual JSON keys reported in the error to see what the API now returns.
  2. Check whether the feed API moved or changed its schema and update the provider's parsing to match.
  3. 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.
  4. If an intermediary (proxy/WAF) is rewriting responses, bypass or fix it so the real feed JSON reaches the provider.
Defensive patterns

Strategy: try-catch

Validate before calling

const json = await res.json();
if (!json || !Array.isArray(json.jobs)) {
  throw new Error(`feed shape changed: keys=${Object.keys(json ?? {}).join(',')}`);
}

Type guard

function isJobsPage(json) {
  return typeof json === 'object' && json !== null && Array.isArray(json.jobs);
}

Try / catch

try {
  const jobs = await fetch4dayweekPage(page);
} catch (e) {
  if (String(e.message).includes('unexpected API response')) {
    console.error('4dayweek feed schema may have changed; inspect the keys in the message');
    return []; // or alert, per policy
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16). Data as JSON: /api/errors/49bec4804fc3093f. Report an issue: GitHub.

Appendix: source

Thrown at providers/4dayweek.mjs:145

/** @type {Provider} */
export default {
  id: '4dayweek',

  detect: detectFourDayEntry,

  async fetch(entry, ctx) {
    assertFourDayUrl(FEED_BASE);
    const maxPages = resolveMaxPages(entry);
    const fallbackCompany = entry?.name;
    const out = [];

    for (let page = 1; page <= maxPages; page++) {
      const url = `${FEED_BASE}?page=${page}`;
      // redirect:'error' prevents SSRF via server-side redirects
      const json = await ctx.fetchJson(url, { redirect: 'error' });
      if (!json || !Array.isArray(json.jobs)) {
        throw new Error(
          `4dayweek: unexpected API response on page ${page} — expected { jobs: [...] }, got keys: [${json ? Object.keys(json).join(', ') : 'null'}]`,
        );
      }
      for (const j of json.jobs) {
        const normalized = normalize4dwJob(j, fallbackCompany);
        if (normalized) out.push(normalized);
      }
      if (json.has_more === false) break; // last page per the API flag
      if (json.jobs.length < PER_PAGE) break; // short page → last page
    }
    return out;
  },
};

View on GitHub (pinned to aac998c7ed)