5

I have a fetch request in React js which calls an API (Node js Backend Server ). For any request made through google chrome which took more than 2 minutes, the fetch request throws me error " Failed to Fetch ". If i pass less parameters ( i.e request for which server took less than 2 minutes), it works fine.

Below is my code.

 fetch(url , requestOptions)
          .then(response => response.blob())
          .then(blob => {
            const newBlob = new Blob( [blob], {type: 'application/zip'});
            const downloadUrl = URL.createObjectURL(newBlob)
                    let a = document.createElement("a"); 
                    a.href = downloadUrl;
                    a.download = "reports";
                    document.body.appendChild(a);
                    a.click();
                    alert(this.state.selectedReport + "Reports Downloaded Successfully")
      
          })
          .catch((error) => {
            alert("Error in downloading report " + error)
        })

Through browsing over internet, i found that there is no timeout parameter in fetch request.

I tried using await and async but it didnt work out and also answers from the below link.

Removing Fetch API default timeout

I want to fetch the data for which backend server take more than 2 minutes. can anyone help me on this.

user2641452
  • 105
  • 2
  • 7

0 Answers0