I am trying to make my Reactjs web application more robust.
I am passing an HTTP request and waiting for the response. and the users of my application are having difficulties with the application because of poor internet connection that keeps disconnecting which results in the application crashing as the HTTP request fails to go through or it fails to return the response.
I am trying to find a solution.
=> I want the application to wait for the internet connection before passing the HTTP request.
I have understood how to detect internet connection using navigator.onLine; but I don't know how to wait till navigator.onLine is true so that I can execute HTTP request.
await axios.post(`https://process.doc.com/v1/tea?key="API_KEY", doc ).then(res=>{console.log(res)})
I want to wait for the internet connection to execute the https request but I can't find a solution.
Expected Result: wait till active internet connection is back so that https request can be made. Actual Result: internet connection is inactive which leads to the application crashing as https request is not made properly