Simply consult the API!
result
was added in version 2020.3.
Prior to that version simply follow the examples from the according version API e.g. 2019.4 API
You can e.g. simply check if there is any content in error
using (var webRequest = UnityWebRequest.Get(uri))
{
yield return webRequest.SendWebRequest();
if (!string.IsNullOrWhiteSpace(webRequest.error))
{
Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
yield break;
}
Debug.Log(webRequest.downloadHandler.text);
}
or if you want to further differentiate isNetworkError
(includes errors like no internet connection, host not reachable, DNS resolve error etc) and isHttpError
(basically same as responseCode >= 400
)
If your question is about downwards compatibility but support both versions either stick to the pre-2020.3 way or use Conditional Compilation and do e.g.
#if UNITY_2020_3_OR_NEWER
if(webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError)
#else
if(!string.IsNullOrWhiteSpace(webRequest.error))
#endif
{
Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
yield break;
}