diff --git a/Samples/TestA/TestA.csproj b/Samples/TestA/TestA.csproj
index d8fea4ab..c786fbf9 100644
--- a/Samples/TestA/TestA.csproj
+++ b/Samples/TestA/TestA.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/Samples/TestB/TestB.csproj b/Samples/TestB/TestB.csproj
index 5ef85438..c30feee6 100644
--- a/Samples/TestB/TestB.csproj
+++ b/Samples/TestB/TestB.csproj
@@ -18,7 +18,7 @@
-
+
diff --git a/Stardust.Server/Controllers/AppController.cs b/Stardust.Server/Controllers/AppController.cs
index 3aea0dba..4cd09b13 100644
--- a/Stardust.Server/Controllers/AppController.cs
+++ b/Stardust.Server/Controllers/AppController.cs
@@ -89,7 +89,7 @@ public class AppController : BaseController
var clientId = model.ClientId;
app ??= _registryService.Register(model.AppId, model.Secret, set.AppAutoRegister, ip, clientId);
- _app = app ?? throw new ApiException(12, "应用鉴权失败");
+ _app = app ?? throw new ApiException(ApiCode.Unauthorized, "应用鉴权失败");
_registryService.Login(app, model, ip, _setting);
@@ -241,7 +241,7 @@ public class AppController : BaseController
private async Task HandleNotify(WebSocket socket, App app, String clientId, String ip, CancellationToken cancellationToken)
{
- if (app == null) throw new ApiException(401, "未登录!");
+ if (app == null) throw new ApiException(ApiCode.Unauthorized, "未登录!");
using var session = new AppCommandSession(socket)
{
@@ -286,10 +286,10 @@ public class AppController : BaseController
var target = App.FindByName(code) ?? throw new ArgumentOutOfRangeException(nameof(model.Code), "无效应用");
var app = _app;
- if (app == null || app.AllowControlNodes.IsNullOrEmpty()) throw new ApiException(401, "无权操作!");
+ if (app == null || app.AllowControlNodes.IsNullOrEmpty()) throw new ApiException(ApiCode.Unauthorized, "无权操作!");
if (app.AllowControlNodes != "*" && !target.Name.EqualIgnoreCase(app.AllowControlNodes.Split(",")))
- throw new ApiException(403, $"[{app}]无权操作应用[{target}]!\n安全设计需要,默认禁止所有应用向其它应用发送控制指令。\n可在注册中心应用系统中修改[{app}]的可控节点,添加[{target.Name}],或者设置为*所有应用。");
+ throw new ApiException(ApiCode.Forbidden, $"[{app}]无权操作应用[{target}]!\n安全设计需要,默认禁止所有应用向其它应用发送控制指令。\n可在注册中心应用系统中修改[{app}]的可控节点,添加[{target.Name}],或者设置为*所有应用。");
var cmd = await _registryService.SendCommand(target, clientId, model, app + "");
@@ -302,7 +302,7 @@ public class AppController : BaseController
[HttpPost(nameof(CommandReply))]
public Int32 CommandReply(CommandReplyModel model)
{
- if (_app == null) throw new ApiException(401, "节点未登录");
+ if (_app == null) throw new ApiException(ApiCode.Unauthorized, "节点未登录");
var cmd = _registryService.CommandReply(_app, model);
@@ -319,7 +319,7 @@ public class AppController : BaseController
info = new Service { Name = serviceName, Enable = true };
info.Insert();
}
- if (!info.Enable) throw new ApiException(403, $"服务[{serviceName}]已停用!");
+ if (!info.Enable) throw new ApiException(ApiCode.Forbidden, $"服务[{serviceName}]已停用!");
return info;
}
diff --git a/Stardust.Server/Controllers/CubeController.cs b/Stardust.Server/Controllers/CubeController.cs
index d41afa83..eb20f6d5 100644
--- a/Stardust.Server/Controllers/CubeController.cs
+++ b/Stardust.Server/Controllers/CubeController.cs
@@ -16,14 +16,14 @@ public class CubeController : ControllerBase
#region 附件
private async Task<(Attachment att, String filePath)> GetFile(String id)
{
- if (id.IsNullOrEmpty()) throw new ApiException(404, "非法附件编号");
+ if (id.IsNullOrEmpty()) throw new ApiException(ApiCode.NotFound, "非法附件编号");
// 去掉仅用于装饰的后缀名
var p = id.IndexOf('.');
if (p > 0) id = id[..p];
var att = Attachment.FindById(id.ToLong());
- if (att == null) throw new ApiException(404, "找不到附件信息");
+ if (att == null) throw new ApiException(ApiCode.NotFound, "找不到附件信息");
var set = StarServerSetting.Current;
@@ -32,14 +32,14 @@ public class CubeController : ControllerBase
if (filePath.IsNullOrEmpty() || !System.IO.File.Exists(filePath))
{
var url = att.Source;
- if (url.IsNullOrEmpty()) throw new ApiException(404, "找不到附件文件");
+ if (url.IsNullOrEmpty()) throw new ApiException(ApiCode.NotFound, "找不到附件文件");
var rs = await att.Fetch(url, set.UploadPath);
- if (!rs) throw new ApiException(404, "附件远程抓取失败");
+ if (!rs) throw new ApiException(ApiCode.NotFound, "附件远程抓取失败");
filePath = att.GetFilePath(set.UploadPath);
}
- if (filePath.IsNullOrEmpty() || !System.IO.File.Exists(filePath)) throw new ApiException(404, "附件文件不存在");
+ if (filePath.IsNullOrEmpty() || !System.IO.File.Exists(filePath)) throw new ApiException(ApiCode.NotFound, "附件文件不存在");
return (att, filePath);
}
diff --git a/Stardust.Server/Controllers/NodeController.cs b/Stardust.Server/Controllers/NodeController.cs
index 2c29577f..30c608eb 100644
--- a/Stardust.Server/Controllers/NodeController.cs
+++ b/Stardust.Server/Controllers/NodeController.cs
@@ -26,23 +26,19 @@ public class NodeController : BaseController
{
private Node _node;
private String _clientId;
- private readonly ICacheProvider _cacheProvider;
private readonly ITracer _tracer;
private readonly IOptions _jsonOptions;
private readonly NodeService _nodeService;
private readonly TokenService _tokenService;
- private readonly DeployService _deployService;
private readonly NodeSessionManager _sessionManager;
private readonly StarServerSetting _setting;
- public NodeController(NodeService nodeService, TokenService tokenService, DeployService deployService, NodeSessionManager sessionManager, StarServerSetting setting, ICacheProvider cacheProvider, IServiceProvider serviceProvider, ITracer tracer, IOptions jsonOptions) : base(serviceProvider)
+ public NodeController(NodeService nodeService, TokenService tokenService, NodeSessionManager sessionManager, StarServerSetting setting, IServiceProvider serviceProvider, ITracer tracer, IOptions jsonOptions) : base(serviceProvider)
{
- _cacheProvider = cacheProvider;
_tracer = tracer;
- this._jsonOptions = jsonOptions;
+ _jsonOptions = jsonOptions;
_nodeService = nodeService;
_tokenService = tokenService;
- _deployService = deployService;
_sessionManager = sessionManager;
_setting = setting;
}
@@ -90,7 +86,7 @@ public class NodeController : BaseController
var oldSecret = node?.Secret;
_node = node;
- if (node != null && !node.Enable) throw new ApiException(99, "禁止登录");
+ if (node != null && !node.Enable) throw new ApiException(ApiCode.Unauthorized, "禁止登录");
// 支持自动识别2020年的XCoder版本,兼容性处理
if (inf.ProductCode.IsNullOrEmpty())
@@ -113,7 +109,7 @@ public class NodeController : BaseController
node ??= _nodeService.Register(inf, ip, _setting);
- if (node == null) throw new ApiException(12, "节点鉴权失败");
+ if (node == null) throw new ApiException(ApiCode.Unauthorized, "节点鉴权失败");
var tokenModel = _nodeService.Login(node, inf, ip, _setting);
@@ -207,7 +203,7 @@ public class NodeController : BaseController
[HttpGet(nameof(Upgrade))]
public UpgradeInfo Upgrade(String channel)
{
- var node = _node ?? throw new ApiException(401, "节点未登录");
+ var node = _node ?? throw new ApiException(ApiCode.Unauthorized, "节点未登录");
// 基础路径
var uri = Request.GetRawUrl().ToString();
@@ -291,7 +287,7 @@ public class NodeController : BaseController
[HttpPost(nameof(Report))]
public async Task