вывод нормальной ошибки от сервера + фикс установки режима работы передатчика

This commit is contained in:
2025-01-16 13:50:01 +03:00
parent cbd2adc1c8
commit 790bfc06c2
7 changed files with 26 additions and 17 deletions

View File

@@ -281,7 +281,7 @@ public:
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
} catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/qos): Can't set QoS settings: " << e.what();
const std::string result = R"({"status":"error"})";
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}
}));
@@ -309,7 +309,7 @@ public:
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
} catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/buclnb): Can't set BUC LNB settings: " << e.what();
const std::string result = R"({"status":"error"})";
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}
}));
@@ -337,7 +337,7 @@ public:
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
} catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/cinc): Can't set CinC settings: " << e.what();
const std::string result = R"({"status":"error"})";
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}
}));
@@ -365,7 +365,7 @@ public:
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
} catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/rxtx): Can't set RX/TX settings: " << e.what();
const std::string result = R"({"status":"error"})";
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}
}));
@@ -393,7 +393,7 @@ public:
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
} catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "WebHandle(/api/set/network): Can't set network settings: " << e.what();
const std::string result = R"({"status":"error"})";
const std::string result = R"({"status": "error", "error": )" + api_driver::buildEscapedString(e.what()) + "}";
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
}
}));

View File

@@ -651,7 +651,7 @@ static const char* boolAsStr(bool value) {
return value ? "true" : "false";
}
static std::string buildEscapedString(const std::string& source) {
std::string api_driver::buildEscapedString(const std::string& source) {
std::string str(source);
size_t start_pos = 0;
while((start_pos = str.find('\"', start_pos)) != std::string::npos) {
@@ -661,7 +661,7 @@ static std::string buildEscapedString(const std::string& source) {
return "\"" + str + "\"";
}
void writeDouble(std::ostream& out, double value, int prec = 2) {
static void writeDouble(std::ostream& out, double value, int prec = 2) {
if (std::isnan(value) || std::isinf(value)) {
out << "\"nan\"";
} else {
@@ -873,7 +873,7 @@ std::string api_driver::ApiDriver::loadSettings() const {
std::stringstream result;
result << "{\n\"txAutoStart\":" << boolAsStr(modSettings.is_save_current_state);
#ifdef MODEM_IS_SCPC
result << ",\"txEn\":" << boolAsStr(!modSettings.tx_is_on);
result << ",\"txEn\":" << boolAsStr(modSettings.tx_is_on);
result << ",\"txModulatorIsTest\":" << boolAsStr(!modSettings.is_carrier);
#endif
result << ",\"txIsTestInput\":" << boolAsStr(modSettings.is_test_data);

View File

@@ -75,6 +75,13 @@ namespace api_driver {
private:
std::unique_ptr<TerminalApiDaemon> daemon;
};
/**
* Функция для создания экранированной строки (для json)
* @param source исходная строка (например, {123"})
* @return {"123\""}
*/
std::string buildEscapedString(const std::string& source);
}
#endif //TERMINAL_API_DRIVER_H