I'm trying to validate an array S3 file URLs whether the file exists using Javascript's fetch() method, and checking if the response returns a 200.
The issue is, whenever I use the validateUrl() method inside filter() via the line:
urls.filter(async (url:string) => await validateUrl(url))
The returned array is not filtered and still contains all URLs even ones that returned a 404 from the validate method.
processUrls(['video-SD','video-HD','video-FHD']);
const validateUrl = async (url: string) => {
const { ok } = await fetch(url, {
method: 'HEAD',
cache: 'no-cache',
mode: 'cors'
});
return ok;
};
const processUrls = (urls: Array<string>) => {
urls.filter(async (url:string) => await validateUrl(url))
}
I'm very confused as to why this happens. Any help would be greatly appreciated.