Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
Validate a URL link

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.

DevTools image

  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
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda