'After updating to unity 2021.1.13.f1 isNetworkError and isHttpError is already obselete

if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }

Does anyone know how to replace this code properly to the updated one



Solution 1:[1]

Starting from Unity 2020.2 you now use UnityWebRequest.result

Example from UnityWebRequest.Get

using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
    // Request and wait for the desired page.
    yield return webRequest.SendWebRequest();

    string[] pages = uri.Split('/');
    int page = pages.Length - 1;

    switch (webRequest.result)
    {
        case UnityWebRequest.Result.ConnectionError:
        case UnityWebRequest.Result.DataProcessingError:
            Debug.LogError(pages[page] + ": Error: " + webRequest.error);
            break;
        case UnityWebRequest.Result.ProtocolError:
            Debug.LogError(pages[page] + ": HTTP Error: " + webRequest.error);
            break;
        case UnityWebRequest.Result.Success:
            Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
            break;
    }
}

Or the simplier example from UnityWebRequest.Post

WWWForm form = new WWWForm();
form.AddField("myField", "myData");

using (UnityWebRequest www = UnityWebRequest.Post("https://www.my-server.com/myform", form))
{
    yield return www.SendWebRequest();

    if (www.result != UnityWebRequest.Result.Success)
    {
        Debug.Log(www.error);
    }
    else
    {
        Debug.Log("Form upload complete!");
    }
}

Solution 2:[2]

I solve mine like that!

instead using: if(www.isNetworkError)

I wrote: if(www.result == UnityWebRequest.Result.ConnectionError)

Full example is below:

 IEnumerator Get(string url)
{
    using (UnityWebRequest www = UnityWebRequest.Get(url))
    {
        yield return www.SendWebRequest();
        
        if (www.result == UnityWebRequest.Result.ConnectionError)
        {
            Debug.LogError(www.error);
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Timóteo A. Cruz