Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!