Skip to content

Commit dc14b42

Browse files
committed
返回Api执行状态
1 parent cc721f3 commit dc14b42

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

WebApiClient/Contexts/ApiActionContext.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ internal async Task PrepareRequestAsync()
8383

8484
/// <summary>
8585
/// 执行请求
86+
/// 返回是否执行成功
8687
/// </summary>
8788
/// <returns></returns>
88-
internal async Task ExecRequestAsync()
89+
internal async Task<bool> ExecRequestAsync()
8990
{
9091
try
9192
{
@@ -94,10 +95,12 @@ internal async Task ExecRequestAsync()
9495

9596
this.ResponseMessage = await client.SendAsync(this.RequestMessage);
9697
this.Result = await apiAction.Return.Attribute.GetTaskResult(this);
98+
return true;
9799
}
98100
catch (Exception ex)
99101
{
100102
this.Exception = ex;
103+
return false;
101104
}
102105
}
103106

WebApiClient/Internal/Tasks/ApiTask.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ private async Task<TResult> RequestAsync()
131131

132132
await context.PrepareRequestAsync();
133133
await context.ExecFiltersAsync(filter => filter.OnBeginRequestAsync);
134-
await context.ExecRequestAsync();
134+
135+
var state = await context.ExecRequestAsync();
135136
await context.ExecFiltersAsync(filter => filter.OnEndRequestAsync);
136137

137-
if (context.Exception != null)
138-
{
139-
throw context.Exception;
140-
}
141-
return (TResult)context.Result;
138+
return state ? (TResult)context.Result : throw context.Exception;
142139
}
143140
}
144141
}

0 commit comments

Comments
 (0)