diff --git a/src/UniTask.NetCore/UniTask.NetCore.csproj b/src/UniTask.NetCore/UniTask.NetCore.csproj index f7a7a2e..5eb881e 100644 --- a/src/UniTask.NetCore/UniTask.NetCore.csproj +++ b/src/UniTask.NetCore/UniTask.NetCore.csproj @@ -36,6 +36,7 @@ ..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\DiagnosticsExtensions.cs; ..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\PlayerLoopRunner.cs; ..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\ContinuationQueue.cs; +..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityWebRequestExtensions.cs; ..\UniTask\Assets\Plugins\UniTask\Runtime\CancellationTokenSourceExtensions.cs; ..\UniTask\Assets\Plugins\UniTask\Runtime\EnumeratorAsyncExtensions.cs; diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs new file mode 100644 index 0000000..33cc593 --- /dev/null +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine.Networking; + +namespace Cysharp.Threading.Tasks.Internal +{ + internal static class UnityWebRequestResultExtensions + { + public static bool IsError(this UnityWebRequest unityWebRequest) + { +#if UNITY_2020_2_OR_NEWER + var result = unityWebRequest.result; + return (result == UnityWebRequest.Result.ConnectionError) + || (result == UnityWebRequest.Result.DataProcessingError) + || (result == UnityWebRequest.Result.ProtocolError); +#else + return unityWebRequest.isHttpError || unityWebRequest.isNetworkError; +#endif + } + } +} \ No newline at end of file diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta new file mode 100644 index 0000000..54bd2eb --- /dev/null +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/UnityWebRequestExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 111ba0e639de1d7428af6c823ead4918 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs index 27b6acd..c5cfbc2 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs @@ -1221,7 +1221,7 @@ namespace Cysharp.Threading.Tasks continuationAction = null; var result = asyncOperation.webRequest; asyncOperation = null; - if (result.isHttpError || result.isNetworkError) + if (result.IsError()) { throw new UnityWebRequestException(result); } @@ -1231,7 +1231,7 @@ namespace Cysharp.Threading.Tasks { var result = asyncOperation.webRequest; asyncOperation = null; - if (result.isHttpError || result.isNetworkError) + if (result.IsError()) { throw new UnityWebRequestException(result); } @@ -1312,7 +1312,7 @@ namespace Cysharp.Threading.Tasks { completed = true; var result = asyncOperation.webRequest; - if (result.isHttpError || result.isNetworkError) + if (result.IsError()) { core.TrySetException(new UnityWebRequestException(result)); } @@ -1470,7 +1470,7 @@ namespace Cysharp.Threading.Tasks if (asyncOperation.isDone) { - if (asyncOperation.webRequest.isHttpError || asyncOperation.webRequest.isNetworkError) + if (asyncOperation.webRequest.IsError()) { core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); } diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt index 31e78dd..d5cac19 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.tt @@ -82,7 +82,7 @@ namespace Cysharp.Threading.Tasks var result = <#= $"asyncOperation.{t.returnField}" #>; asyncOperation = null; <# if(t.returnType == "UnityWebRequest") { #> - if (result.isHttpError || result.isNetworkError) + if (result.IsError()) { throw new UnityWebRequestException(result); } @@ -98,7 +98,7 @@ namespace Cysharp.Threading.Tasks var result = <#= $"asyncOperation.{t.returnField}" #>; asyncOperation = null; <# if(t.returnType == "UnityWebRequest") { #> - if (result.isHttpError || result.isNetworkError) + if (result.IsError()) { throw new UnityWebRequestException(result); } @@ -184,7 +184,7 @@ namespace Cysharp.Threading.Tasks completed = true; <# if(t.returnType == "UnityWebRequest") { #> var result = asyncOperation.webRequest; - if (result.isHttpError || result.isNetworkError) + if (result.IsError()) { core.TrySetException(new UnityWebRequestException(result)); } @@ -362,7 +362,7 @@ namespace Cysharp.Threading.Tasks if (asyncOperation.isDone) { <# if(t.returnType == "UnityWebRequest") { #> - if (asyncOperation.webRequest.isHttpError || asyncOperation.webRequest.isNetworkError) + if (asyncOperation.webRequest.IsError()) { core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest)); }