60 lines
2.4 KiB
C++
60 lines
2.4 KiB
C++
#include "UpdateErrorMessage.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
namespace GUI {
|
|
|
|
wxDEFINE_EVENT(EVT_UPDATE_ERROR_MESSAGE, wxCommandEvent);
|
|
|
|
std::string show_error_message(int error_code)
|
|
{
|
|
char buf[64];
|
|
std::string result_str = "";
|
|
std::sprintf(buf,"%08X",error_code);
|
|
std::string hms_host = wxGetApp().app_config->get_hms_host();
|
|
std::string get_lang = wxGetApp().app_config->get_langauge_code();
|
|
|
|
std::string url = (boost::format("https://%1%/query.php?lang=%2%&e=%3%")
|
|
%hms_host
|
|
%get_lang
|
|
%buf).str();
|
|
|
|
Slic3r::Http http = Slic3r::Http::get(url);
|
|
http.header("accept", "application/json")
|
|
.timeout_max(10)
|
|
.on_complete([get_lang, &result_str](std::string body, unsigned status) {
|
|
try {
|
|
json j = json::parse(body);
|
|
if (j.contains("result")) {
|
|
if (j["result"].get<int>() == 0) {
|
|
if (j.contains("data")) {
|
|
json jj = j["data"];
|
|
if (jj.contains("device_error")) {
|
|
if (jj["device_error"].contains(get_lang)) {
|
|
if (jj["device_error"][get_lang].size() > 0) {
|
|
if (!jj["device_error"][get_lang][0]["intro"].empty() || !jj["device_error"][get_lang][0]["ecode"].empty()) {
|
|
std::string error_info = jj["device_error"][get_lang][0]["intro"].get<std::string>();
|
|
std::string error_code = jj["device_error"][get_lang][0]["ecode"].get<std::string>();
|
|
error_code.insert(4, " ");
|
|
result_str = from_u8(error_info).ToStdString() + "[" + error_code + "]";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (...) {
|
|
;
|
|
}
|
|
})
|
|
.on_error([](std::string body, std::string error, unsigned status) {
|
|
BOOST_LOG_TRIVIAL(trace) << boost::format("[BBL ErrorMessage]: status=%1%, error=%2%, body=%3%") % status % error % body;
|
|
}).perform_sync();
|
|
|
|
return result_str;
|
|
}
|
|
|
|
}
|
|
} |