添加基础api控制器异常响应结果

This commit is contained in:
FalconFly 2023-12-18 09:49:07 +08:00
parent 0a85919d2d
commit ed42d18013

View File

@ -247,6 +247,21 @@ namespace Falcon.SugarApi.ApiDefinistions
protected virtual async Task<ApiResult<T>> FailResultAsync<T>(string failMessage)
=> await Task.FromResult(FailResult<T>(failMessage));
/// <summary>
/// 异步返回api错误信息和异常信息
/// </summary>
/// <typeparam name="T">返回数据类型</typeparam>
/// <param name="failMessage">错误信息</param>
/// <param name="ex">产生的异常</param>
/// <returns>api异常结果</returns>
protected virtual async Task<ApiResult<T>> ExceptionResultAsync<T>(string failMessage,Exception ex) {
var result = FailResult<T>(f => {
f.Msg = failMessage;
f.Exception = ex.ToString();
});
return await Task.FromResult(result);
}
#endregion
#region