Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda