await UnityWebRequestAsyncOperation throws UnityWebRequestException when isHttpError or isNetworkError
parent
a2783d3c8a
commit
00a1be8666
|
@ -1285,12 +1285,20 @@ namespace Cysharp.Threading.Tasks
|
|||
continuationAction = null;
|
||||
var result = asyncOperation.webRequest;
|
||||
asyncOperation = null;
|
||||
if (result.isHttpError || result.isNetworkError)
|
||||
{
|
||||
throw new UnityWebRequestException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = asyncOperation.webRequest;
|
||||
asyncOperation = null;
|
||||
if (result.isHttpError || result.isNetworkError)
|
||||
{
|
||||
throw new UnityWebRequestException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -1367,7 +1375,15 @@ namespace Cysharp.Threading.Tasks
|
|||
else
|
||||
{
|
||||
completed = true;
|
||||
core.TrySetResult(asyncOperation.webRequest);
|
||||
var result = asyncOperation.webRequest;
|
||||
if (result.isHttpError || result.isNetworkError)
|
||||
{
|
||||
core.TrySetException(new UnityWebRequestException(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
core.TrySetResult(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1525,8 +1541,15 @@ namespace Cysharp.Threading.Tasks
|
|||
}
|
||||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
if (asyncOperation.webRequest.isHttpError || asyncOperation.webRequest.isNetworkError)
|
||||
{
|
||||
core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest));
|
||||
}
|
||||
else
|
||||
{
|
||||
core.TrySetResult(asyncOperation.webRequest);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,12 @@ namespace Cysharp.Threading.Tasks
|
|||
<# if (!IsVoid(t)) { #>
|
||||
var result = <#= $"asyncOperation.{t.returnField}" #>;
|
||||
asyncOperation = null;
|
||||
<# if(t.returnType == "UnityWebRequest") { #>
|
||||
if (result.isHttpError || result.isNetworkError)
|
||||
{
|
||||
throw new UnityWebRequestException(result);
|
||||
}
|
||||
<# } #>
|
||||
return result;
|
||||
<# } else { #>
|
||||
asyncOperation = null;
|
||||
|
@ -91,6 +97,12 @@ namespace Cysharp.Threading.Tasks
|
|||
<# if (!IsVoid(t)) { #>
|
||||
var result = <#= $"asyncOperation.{t.returnField}" #>;
|
||||
asyncOperation = null;
|
||||
<# if(t.returnType == "UnityWebRequest") { #>
|
||||
if (result.isHttpError || result.isNetworkError)
|
||||
{
|
||||
throw new UnityWebRequestException(result);
|
||||
}
|
||||
<# } #>
|
||||
return result;
|
||||
<# } else { #>
|
||||
asyncOperation = null;
|
||||
|
@ -170,7 +182,19 @@ namespace Cysharp.Threading.Tasks
|
|||
else
|
||||
{
|
||||
completed = true;
|
||||
<# if(t.returnType == "UnityWebRequest") { #>
|
||||
var result = asyncOperation.webRequest;
|
||||
if (result.isHttpError || result.isNetworkError)
|
||||
{
|
||||
core.TrySetException(new UnityWebRequestException(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
core.TrySetResult(result);
|
||||
}
|
||||
<# } else { #>
|
||||
core.TrySetResult(<#= IsVoid(t) ? "AsyncUnit.Default" : $"asyncOperation.{t.returnField}" #>);
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -345,7 +369,18 @@ namespace Cysharp.Threading.Tasks
|
|||
|
||||
if (asyncOperation.isDone)
|
||||
{
|
||||
<# if(t.returnType == "UnityWebRequest") { #>
|
||||
if (asyncOperation.webRequest.isHttpError || asyncOperation.webRequest.isNetworkError)
|
||||
{
|
||||
core.TrySetException(new UnityWebRequestException(asyncOperation.webRequest));
|
||||
}
|
||||
else
|
||||
{
|
||||
core.TrySetResult(asyncOperation.webRequest);
|
||||
}
|
||||
<# } else { #>
|
||||
core.TrySetResult(<#= IsVoid(t) ? "AsyncUnit.Default" : $"asyncOperation.{t.returnField}" #>);
|
||||
<# } #>
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#if ENABLE_UNITYWEBREQUEST
|
||||
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public class UnityWebRequestException : Exception
|
||||
{
|
||||
public UnityWebRequest UnityWebRequest { get; }
|
||||
public bool IsNetworkError { get; }
|
||||
public bool IsHttpError { get; }
|
||||
|
||||
public UnityWebRequestException(UnityWebRequest unityWebRequest)
|
||||
: base(unityWebRequest.error + Environment.NewLine + unityWebRequest.downloadHandler.text)
|
||||
{
|
||||
this.UnityWebRequest = unityWebRequest;
|
||||
this.IsNetworkError = unityWebRequest.isNetworkError;
|
||||
this.IsHttpError = unityWebRequest.isHttpError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 013a499e522703a42962a779b4d9850c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -415,15 +415,12 @@ public class SandboxMain : MonoBehaviour
|
|||
|
||||
private async UniTaskVoid ExecuteAsync()
|
||||
{
|
||||
Debug.Log("1");
|
||||
{
|
||||
var xs = await UniTaskAsyncEnumerable.TimerFrame(1).ToArrayAsync();
|
||||
}
|
||||
Debug.Log("------------------");
|
||||
{
|
||||
var xs = await UniTaskAsyncEnumerable.TimerFrame(1).ToArrayAsync();
|
||||
Debug.Log("2");
|
||||
}
|
||||
var req = UnityWebRequest.Get("https://google.com/");
|
||||
|
||||
var v = await req.SendWebRequest().ToUniTask();
|
||||
// req.Dispose();
|
||||
Debug.Log($"{v.isDone} {v.isHttpError} {v.isNetworkError}");
|
||||
Debug.Log(v.downloadHandler.text);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue