Skip to content

Commit

Permalink
don't use deprecate www fields in newer versions of Unity
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Gehorsam committed Aug 14, 2021
1 parent 2ba89c4 commit 402e31b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Packages/Nakama/Runtime/UnityWebRequestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ private static IEnumerator SendRequest(UnityWebRequest www, Action<string> callb
Action<ApiResponseException> errback)
{
yield return www.SendWebRequest();
if (www.isNetworkError)
if (IsNetworkError(www))
{
errback(new ApiResponseException(www.error));
}
else if (www.isHttpError)
else if (IsHttpError(www))
{
var decoded = www.downloadHandler.text.FromJson<Dictionary<string, object>>();

Expand All @@ -146,5 +146,23 @@ private static IEnumerator SendRequest(UnityWebRequest www, Action<string> callb
callback?.Invoke(www.downloadHandler?.text);
}
}

private static bool IsNetworkError(UnityWebRequest www)
{
#if UNITY_2020_2_OR_NEWER
return www.result == UnityWebRequest.Result.ConnectionError;
#else
return www.isNetworkError;
#endif
}

private static bool IsHttpError(UnityWebRequest www)
{
#if UNITY_2020_2_OR_NEWER
return www.result == UnityWebRequest.Result.ProtocolError;
#else
return www.isHttpError;
#endif
}
}
}

0 comments on commit 402e31b

Please sign in to comment.