mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新Demo
更新Demo
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#if ENABLE_UNITYWEBREQUEST && (!UNITY_2019_1_OR_NEWER || UNITASK_WEBREQUEST_SUPPORT)
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public class UnityWebRequestException : Exception
|
||||
{
|
||||
public UnityWebRequest UnityWebRequest { get; }
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
public UnityWebRequest.Result Result { get; }
|
||||
#else
|
||||
public bool IsNetworkError { get; }
|
||||
public bool IsHttpError { get; }
|
||||
#endif
|
||||
public string Error { get; }
|
||||
public string Text { get; }
|
||||
public long ResponseCode { get; }
|
||||
public Dictionary<string, string> ResponseHeaders { get; }
|
||||
|
||||
string msg;
|
||||
|
||||
public UnityWebRequestException(UnityWebRequest unityWebRequest)
|
||||
{
|
||||
this.UnityWebRequest = unityWebRequest;
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
this.Result = unityWebRequest.result;
|
||||
#else
|
||||
this.IsNetworkError = unityWebRequest.isNetworkError;
|
||||
this.IsHttpError = unityWebRequest.isHttpError;
|
||||
#endif
|
||||
this.Error = unityWebRequest.error;
|
||||
this.ResponseCode = unityWebRequest.responseCode;
|
||||
if (UnityWebRequest.downloadHandler != null)
|
||||
{
|
||||
if (unityWebRequest.downloadHandler is DownloadHandlerBuffer dhb)
|
||||
{
|
||||
this.Text = dhb.text;
|
||||
}
|
||||
}
|
||||
this.ResponseHeaders = unityWebRequest.GetResponseHeaders();
|
||||
}
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
if (msg == null)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(Text))
|
||||
{
|
||||
msg = Error + Environment.NewLine + Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = Error;
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user