[LCEngineFunction("asyncException")]
public static async Task<string> AsyncException()
{
await Task.Delay(500);
throw new LCException(400, "error message");
//返回结果 Exception of type 'LeanCloud.LCException' was thrown.
}
在.Net 异步云函数中, Throw LCException 后会响应 Exception of type 'LeanCloud.LCException' was thrown.
但在同步云函数中,则会返回 JSON Object {"code":400,"message":"error message"}
如果希望在异步云函数中,也同样返回JSON Object,应该要怎样做?
目前我的做法是手动在每个云函数中将LCException转换成一般的Excetion(Message设成JSON Object), 但这个不是正确方法对吧
[LCEngineFunction("asyncExceptionFixed")]
public static async Task<string> AsyncExceptionFixed()
{
try
{
await Task.Delay(500);
throw new LCException(400, "error message");
}
catch (LCException e)
{
throw new Exception(JsonConvert.SerializeObject(new { code = e.Code, message = e.Message }));
//返回结果 {"code":400,"message":"error message"}
}
}