mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
impr: Improve network interface error handling
This commit is contained in:
@@ -28,13 +28,17 @@ namespace hex::plugin::builtin {
|
||||
|
||||
const auto &endpoints = ContentRegistry::CommunicationInterface::impl::getNetworkEndpoints();
|
||||
if (auto callback = endpoints.find(json["endpoint"].get<std::string>()); callback != endpoints.end()) {
|
||||
log::info("Network endpoint {} called with arguments '{}'", json["endpoint"].get<std::string>(), json.contains("data") ? json["data"].dump() : "");
|
||||
|
||||
auto responseData = callback->second(json.contains("data") ? json["data"] : nlohmann::json::object());
|
||||
|
||||
result["status"] = "success";
|
||||
result["data"] = responseData;
|
||||
} else {
|
||||
throw std::runtime_error("Endpoint not found");
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
log::error("Network interface service error: {}", e.what());
|
||||
log::warn("Network interface service error: {}", e.what());
|
||||
|
||||
result["status"] = "error";
|
||||
result["data"]["error"] = e.what();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace hex::plugin::builtin {
|
||||
|
||||
void registerNetworkEndpoints() {
|
||||
ContentRegistry::CommunicationInterface::registerNetworkEndpoint("pattern_editor/set_code", [](const nlohmann::json &data) -> nlohmann::json {
|
||||
auto code = data["code"].get<std::string>();
|
||||
auto code = data.at("code").get<std::string>();
|
||||
|
||||
EventManager::post<RequestSetPatternLanguageCode>(code);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user