impr: Improve network interface error handling

This commit is contained in:
WerWolv
2023-05-16 11:20:46 +02:00
parent a758676b0d
commit 7e9b23de7d
2 changed files with 6 additions and 2 deletions

View File

@@ -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();

View File

@@ -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);