fix rpc ex , add RpcError Method
This commit is contained in:
@@ -71,6 +71,7 @@ public partial class Synapse
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("Synapse RPC 方法异常: {Err}\n{Stack}", ex.Message,ex.StackTrace);
|
||||
res = new SimApiBaseResponse(500, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ using MQTTnet.Formatter;
|
||||
using SimApi.Attributes;
|
||||
using SimApi.Communications;
|
||||
using SimApi.Configurations;
|
||||
using SimApi.Exceptions;
|
||||
using SimApi.Helpers;
|
||||
|
||||
namespace SimApi;
|
||||
@@ -116,6 +117,18 @@ public partial class Synapse(SimApiOptions simApiOptions, ILogger<Synapse> logge
|
||||
return Rpc<object>(appName, method, param);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 只能在Rpc方法中使用,快捷抛出异常返回
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <exception cref="SimApiException"></exception>
|
||||
public void RpcError(int code, string message = "")
|
||||
{
|
||||
throw new SimApiException(code, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user