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

109
Visualizações
logging custom error fecth api javascript
 const Home =() => {
 const [posts, setPosts] = useState([]);
 const [error, setError] = useState(null); 
 const loadPosts = () => {
        getPost()
          .then((response) => {
            if (!response.ok) {
              throw Error("Server not reachable!");
            }
            return response.json();
          })
          .then((data) => {
            setPosts(data.posts);
          })
          .catch((err) => {
            setError(err.message);
          });
      };

return(
 <div>{error} </div>
)
}

i am trying to log the custom error that i have throw i.e "Server not reachable!", but for some reason i am always getting the default error log i.e fail to fetch

How can i log the custom error that i have throw instead of the default one

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