I simply want to validate that a link to help text is a valid link when entering the link in a CRUD operation. When I use fetch it fails if the link is to an invalid site, however, not if it is to a bad page on a site (404). The response from the fetch is the same to both a valid page and a non-vaid page, yet google Chrome seems to know.
const g_log1 = true
if (g_log1) console.log('URL ', url)
try {
const urlOptions = {
method: 'HEAD',
mode: 'no-cors',
headers: { 'Content-Type': 'application/json' }
}
fetch(url, urlOptions)
.then(response => {
if (g_log1) console.log(url, '--1--', response)
return true
})
.catch(error => {
if (g_log1) console.log(url, '--2--', error)
return false
})
} catch (error) {
if (g_log1) console.log(url, '--3--', error)
return false
}
}
export default apiCheckURL