Compare commits

...
3 Commits
Author SHA1 Message Date
xrain 8f6b853b6c fix rpc ex , add RpcError Method 2024-08-25 00:11:00 +08:00
xrain e876486c00 fix rpc ex , add RpcError Method 2024-08-25 00:10:00 +08:00
xrain e71226be4a fix rpc ex , add RpcError Method 2024-08-25 00:08:06 +08:00
2 changed files with 26 additions and 1 deletions
+1
View File
@@ -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);
}
}
+25 -1
View File
@@ -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,8 +117,31 @@ 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>
/// <param name="condition"></param>
/// <param name="code"></param>
/// <param name="message"></param>
public void RpcErrorWhen(bool condition, int code, string message = "")
{
if (condition) RpcError(code, message);
}
/// <summary>
/// 发送一个事件
/// </summary>
/// <param name="eventName"></param>
/// <param name="param"></param>