网络异常处理
This commit is contained in:
parent
8c5ad08475
commit
c0ebe80a1f
@ -15,6 +15,8 @@ namespace Assets.Scripts.Apis
|
|||||||
{
|
{
|
||||||
protected async override Task<HttpResponseMessage> SendAsync(
|
protected async override Task<HttpResponseMessage> SendAsync(
|
||||||
HttpRequestMessage request, CancellationToken cancellationToken)
|
HttpRequestMessage request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
|
||||||
//{"result":false,"errMsg":"已在其他设备登录","code":401}
|
//{"result":false,"errMsg":"已在其他设备登录","code":401}
|
||||||
@ -32,8 +34,24 @@ namespace Assets.Scripts.Apis
|
|||||||
{
|
{
|
||||||
App.is401 = null;
|
App.is401 = null;
|
||||||
}
|
}
|
||||||
|
if (response.StatusCode != System.Net.HttpStatusCode.OK)
|
||||||
|
{
|
||||||
|
response.Content = new StringContent(new JsonResult<object> { result = false, errMsg = "Please check if the network connection is normal.", data = null }.ToString());
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Log(e);
|
||||||
|
HttpResponseMessage httpResponse = new HttpResponseMessage
|
||||||
|
{
|
||||||
|
StatusCode = System.Net.HttpStatusCode.BadRequest,
|
||||||
|
Content = new StringContent(new JsonResult<object> { result = false, errMsg = "Please check if the network connection is normal.", data = null }.ToString())
|
||||||
|
};
|
||||||
|
return httpResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
private T ParseJson<T>(string result)
|
private T ParseJson<T>(string result)
|
||||||
{
|
{
|
||||||
return JsonConvert.DeserializeObject<T>(result, new JsonSerializerSettings
|
return JsonConvert.DeserializeObject<T>(result, new JsonSerializerSettings
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user