How to handle UnityWebRequest Errors when throws Curl 28 Error

I want to handle when web request throw an error.

 UnityWebRequest webRequest = UnityWebRequest.Post("", form);
 webRequest.timeout = 3;
yield return webRequest.SendWebRequest();

if (webRequest.isNetworkError || webRequest.isHttpError)
       Debug.Log("Error: time out");
        var s = webRequest.downloadHandler.text;

This script throws an exception Curl error 28: Connection timed out after 2000 milliseconds.

I tried to put webRequest.,isNetwotkError into the try catch block but it does not work the application crashed. What do you advice ? How can I handle the network errors ?

I’m in need of this also - anyone have a solution?

Same issue, can’t handle, has no idea

Same here. I am spawning a bunch of requests that I know will likely fail. I’d like them to fail quietly without spamming the console. Has anyone found a solution? Thanks!

Hello @ctykaya . I was having your same problem. It is unacceptable to show errors in console, so to fix it, I think the solution is not so optimal. There it goes:

instead of:

webRequest.timeout = 3;

yield return webRequest.SendWebRequest();

try this:


n = 3;

while (n > 0)
	if (n == 0) //3f is webRequest.timeout
	if (webRequest.isDone) break;

	yield return new WaitForSeconds(1f); //adjust the interval of verify

Also, you should use using in this line:

UnityWebRequest webRequest = UnityWebRequest.Post("", form)

the only solution is changing the code from coroutine to async methods and use try catch