Review sitemap validator failures before the happy path

Review sitemap validator failures before the happy path

●3 ●53
calendar_today ago • schedule2 min read
— Originally published at chriseugenerodriguez.com

Review the failure cases before trusting the green path

Start with Node.js and a source of absolute sitemap URLs. You also need a fetch-compatible dependency that can expose a response status and headers. The useful test setup is not a browser or a crawler simulation: it is a recording or stubbed fetch dependency that makes the validator’s request options and returned response observable.

The failure assertions define the contract. A sitemap URL that produces 301 must be reported as a redirect. A 200 response with X-Robots-Tag: googlebot: noindex, nofollow must be rejected as a noindex-header failure. The validator must also request manual redirect handling; otherwise a normal fetch can follow the redirect and replace the evidence with the destination’s 200 response.

That leads to one implementation decision: preserve a structured list of problems rather than collapsing every result into a boolean. A direct 200 with no blocking header has an empty list and succeeds. A redirect gets redirect. A non-2xx, non-3xx result gets a status-specific failure. Header directives are normalized and split so noindex or none can be detected even when combined with other directives or crawler qualifiers.

The expected result is an actionable response record per sitemap URL: status, raw header value, problem categories, and an overall pass/fail field. It identifies whether the mismatch belongs to the sitemap, route configuration, application response, or header configuration. The injected dependency also proves the validator requests manual redirect handling; it does not claim a browser or external search engine observed the URL.

One important limitation remains: this is a response-level release check, not an indexing verdict. It cannot prove a crawler has visited the page. It also does not detect an HTML <meta name="robots"> directive, because that requires a separate fetch-and-parse step. Keeping those concerns apart makes the failure report honest and the validator easier to maintain.

Working example

/**
 * Checks the response currently served for each sitemap URL. This is a deployment
 * check only: it cannot determine whether Google has crawled or indexed a URL.
 * HTML robots meta tags require fetching and parsing the HTML separately.
 */
export async function checkSitemapUrls(urls, fetchFn) {
  if (!Array.isArray(urls)) throw new TypeError('urls must be an array');
  if (typeof fetchFn !== 'function') throw new TypeError('fetchFn must be a function');

  return Promise.all(urls.map(async (url) => {
    const response = await fetchFn(url, { redirect: 'manual' });
    const xRobotsTag = response.headers?.get?.('x-robots-tag') ?? '';
    const directives = xRobotsTag.toLowerCase().split(/[\s,]+/);
    const problems = [];

    if (response.status >= 300 && response.status < 400) {
      problems.push('redirect');
    } else if (response.status < 200 || response.status >= 300) {
      problems.push(`http-${response.status}`);
    }

    if (directives.includes('noindex') || directives.includes('none')) {
      problems.push('noindex-header');
    }

    return {
      url,
      status: response.status,
      xRobotsTag,
      problems,
      ok: problems.length === 0,
    };
  }));
}

Read the full article: https://chriseugenerodriguez.com/blog/check-sitemap-urls-for-redirects-and-noindex

Want more #programming deep dives?

Join 6,101+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelski - Apr 23

Frameworks Are Institutional Memory

Ken W. Algerverified - Sep 17

Your Tech Stack Isn’t Your Ceiling. Your Story Is

Karol Modelski - Apr 9

I’m a Senior Dev and I’ve Forgotten How to Think Without a Prompt

Karol Modelski - Mar 19

A Message From Our Founder: On the Winding Down of LaaSy™

Ken W. Algerverified - Oct 29
chevron_left
1.1k Points • 56 Badges
Santa Monica, CA • chriseugenerodriguez.com
42Posts
0Comments
11Connections
10 years fe

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!