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

153
Vistas
How to show error message only one time when give status code 500
useEffect(() => {
  setTimeout(async () => {
    await fetch(url)
      .then((res) => res.json())
      .then((data) => {
        if (Object.keys(data).length !== 0) {
          setIsLoaded(true);
          setRoundTrip(data);
        } else {
          Swal.fire({
            icon: "error",
            title: "Oops...",
            text: "No Flights Found",
            confirmButtonText: "Search Again...",
          })
            .then(function () {
              navigate("/");
            });
        }
      });
  }, 1000);
}, [url]);

It gives me the error message multiple time but I want to show the error message only one time then it should stop fetching.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can set conditions for res.status.

useEffect(() => {
  setTimeout(async () => {
    await fetch(url)
      .then((res) => res.json())
      .then((data) => {
        //here is solution
        if(res.status === 500){
           Swal.fire({
            icon: "error",
            title: "Oops...",
            text: "No Flights Found",
            confirmButtonText: "Search Again...",
          })
            .then(function () {
              navigate("/");
            });
        }

        if (Object.keys(data).length !== 0) {
          setIsLoaded(true);
          setRoundTrip(data);
        } 
          
        
      });
  }, 1000);
}, [url]);
about 4 years ago · Juan Pablo Isaza Denunciar
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