change CORS interface, add try-catch handler
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
#include "IPTable.h"
|
||||
#include <webcc/view.h>
|
||||
#include "FileReceiver.h"
|
||||
#include "ServerLogger.h"
|
||||
#include "ServerProcessor.h"
|
||||
#include "SyncFileReceiver.h"
|
||||
#include "HTTPObjectsBridge.h" // 确保能看到 Request::Impl 结构体
|
||||
#include "UNSResponseBuilder.h"
|
||||
|
||||
namespace uns
|
||||
{
|
||||
@@ -13,7 +16,7 @@ namespace uns
|
||||
public:
|
||||
virtual ~IBlockedIpUpdatable() = default;
|
||||
|
||||
// 统一的库内更新接口(这里的 YourIPContainerType 请替换为你 BlockedIPs 的实际类型)
|
||||
// 统一的库内更新接口
|
||||
virtual void ApplyIpUpdate(IPTablePtr blocked_ips) = 0;
|
||||
};
|
||||
|
||||
@@ -32,20 +35,55 @@ namespace uns
|
||||
// 完美的把 webcc 的驱动流,翻译给用户的纯净业务类
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) final
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_processor->Handle(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
try
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_processor->Handle(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in ServerProcessorAdapter(Handle): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in ServerProcessorAdapter(Handle)");
|
||||
}
|
||||
return uns::ResponseBuilder().InternalServerError()()->GetImpl()->webcc_res; //Default 500
|
||||
}
|
||||
|
||||
bool Stream(const std::string& method) final
|
||||
{
|
||||
return user_processor->Stream(method);
|
||||
try
|
||||
{
|
||||
return user_processor->Stream(method);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in ServerProcessorAdapter(Stream): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in ServerProcessorAdapter(Stream)");
|
||||
}
|
||||
return false; //Default false
|
||||
}
|
||||
|
||||
void ApplyIpUpdate(IPTablePtr blocked_ips) override
|
||||
{
|
||||
user_processor->UpdateBlockedIPList(blocked_ips);
|
||||
try
|
||||
{
|
||||
user_processor->UpdateBlockedIPList(blocked_ips);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in ServerProcessorAdapter(ApplyIpUpdate): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in ServerProcessorAdapter(ApplyIpUpdate)");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -62,10 +100,22 @@ namespace uns
|
||||
// 完美的把 webcc 的驱动流,翻译给用户的纯净业务类
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) final
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_reciver->Execute(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
try
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_reciver->Execute(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in FileReceiverAdapter(Handle): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in FileReceiverAdapter(Handle)");
|
||||
}
|
||||
return uns::ResponseBuilder().InternalServerError()()->GetImpl()->webcc_res; //Default 500
|
||||
}
|
||||
|
||||
bool Stream(const std::string& method) final
|
||||
@@ -76,7 +126,18 @@ namespace uns
|
||||
|
||||
void ApplyIpUpdate(IPTablePtr blocked_ips) override
|
||||
{
|
||||
user_reciver->UpdateBlockedIPs(blocked_ips);
|
||||
try
|
||||
{
|
||||
user_reciver->UpdateBlockedIPs(blocked_ips);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in FileReceiverAdapter(ApplyIpUpdate): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in FileReceiverAdapter(ApplyIpUpdate)");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,10 +154,22 @@ namespace uns
|
||||
// 完美的把 webcc 的驱动流,翻译给用户的纯净业务类
|
||||
webcc::ResponsePtr Handle(webcc::RequestPtr request) final
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_reciver->Execute(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
try
|
||||
{
|
||||
auto uns_req = uns::RequestPtr(new uns::Request(std::make_unique<uns::Request::Impl>(request)));
|
||||
// 调用用户的业务类
|
||||
uns::ResponsePtr uns_res = user_reciver->Execute(uns_req);
|
||||
return uns_res->GetImpl()->webcc_res;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in SyncFileReceiverAdapter(Handle): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in SyncFileReceiverAdapter(Handle)");
|
||||
}
|
||||
return uns::ResponseBuilder().InternalServerError()()->GetImpl()->webcc_res; //Default 500
|
||||
}
|
||||
|
||||
bool Stream(const std::string& method) final
|
||||
@@ -107,7 +180,18 @@ namespace uns
|
||||
|
||||
void ApplyIpUpdate(IPTablePtr blocked_ips) override
|
||||
{
|
||||
user_reciver->UpdateBlockedIPs(blocked_ips);
|
||||
try
|
||||
{
|
||||
user_reciver->UpdateBlockedIPs(blocked_ips);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
SCLOGF_ERROR("Unhandled Exception in SyncFileReceiverAdapter(ApplyIpUpdate): {}", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
SCLOGF_FATAL("Unhandled Unknown Exception in SyncFileReceiverAdapter(ApplyIpUpdate)");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user