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

154
Visualizações
FetchAPI Response on DNS failure

I am trying something like:

const resp = await fetch('http://bad-domain'); //bad-domain does not resolve

I am then catching an exception later in my code that reads: TypeError: failed to fetch

Is this the expected result of a failed DNS lookup or is this due to resp coming out as different from the normal Response object that an error free fetch returns.

It is just that TypeError does not clearly indicate that the issue is a bad network request and not bad javascript code.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's the expected behavior:

12.3. If response is a network error, then reject p with a TypeError and terminate these substeps.

...where p is the promise returned by fetch. The specification doesn't require any specific information be provided about why the request failed, just that it failed (at the network level; it doesn't reject on HTTP errors, as I describe here on my old anemic blog, you have to check that on the fulfillment path).

about 4 years ago · Juan Pablo Isaza Relatório
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