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;
|
||||
if (status >= 400 && status < 500) {
|
||||
try {
|
||||
json j = json::parse(evt.GetString());
|
||||
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>();
|
||||
wxString body_str = evt.GetString();
|
||||
bool found_json = false;
|
||||
for (int i = 0; i < body_str.size(); i++) {
|
||||
if (body_str[i] == '{') {
|
||||
found_json = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 (...) {}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue