How to validate HTTP status codes for URLs stored in Airtable records

I’m working with an Airtable base that contains approximately 24,000 website URLs. Many of these URLs have formatting issues like missing slashes or extra spaces that cause them to break. I need a way to check which URLs are problematic so I can fix them manually.

Current approach
I’ve been using a fetch-based script to test each URL and get status information:

const config = input.config();
const websiteUrl = config.websiteUrl;
let responseStatus;

try {
    const request = await fetch(websiteUrl);
    responseStatus = request.status;
} catch (err) {
    responseStatus = 'failed';
}

output.set('responseStatus', responseStatus);

Problems I’m facing

  1. When URLs redirect to other pages, my script treats them as errors instead of following the redirect chain
  2. I only get “200” for working URLs or “failed” for broken ones. I want to see the actual HTTP status codes like 404, 500, etc.

Does anyone know how to modify this script to handle redirects properly and capture specific error codes? Any suggestions would be helpful!

try adding {redirect: 'follow'} to your fetch call - that’ll handle redirects automatically. also, your catch block might be hiding the actual error codes. log the real error first so you can see what’s going on.