ENH: avoid crash when http return body is not a json
Change-Id: I4d0d3bae9847ab2f9a9cf6f3affa593bec4ab411 Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
parent
b9abdbe4f8
commit
4e778539b8
|
@ -4022,14 +4022,25 @@ void GUI_App::on_http_error(wxCommandEvent &evt)
|
||||||
wxString result;
|
wxString result;
|
||||||
if (status >= 400 && status < 500) {
|
if (status >= 400 && status < 500) {
|
||||||
try {
|
try {
|
||||||
json j = json::parse(evt.GetString());
|
wxString body_str = evt.GetString();
|
||||||
if (j.contains("code")) {
|
bool found_json = false;
|
||||||
if (!j["code"].is_null())
|
for (int i = 0; i < body_str.size(); i++) {
|
||||||
code = j["code"].get<int>();
|
if (body_str[i] == '{') {
|
||||||
}
|
found_json = true;
|
||||||
if (j.contains("error"))
|
break;
|
||||||
if (!j["error"].is_null())
|
}
|
||||||
error = j["error"].get<std::string>();
|
}
|
||||||
|
if (found_json) {
|
||||||
|
json j = json::parse(body_str);
|
||||||
|
if (j.contains("code")) {
|
||||||
|
if (!j["code"].is_null())
|
||||||
|
code = j["code"].get<int>();
|
||||||
|
}
|
||||||
|
if (j.contains("error")) {
|
||||||
|
if (!j["error"].is_null())
|
||||||
|
error = j["error"].get<std::string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (...) {}
|
catch (...) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue