From 4e778539b855bfb315b9dbdf7a91779401471125 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Thu, 15 Jun 2023 08:49:53 +0800 Subject: [PATCH] ENH: avoid crash when http return body is not a json Change-Id: I4d0d3bae9847ab2f9a9cf6f3affa593bec4ab411 Signed-off-by: Stone Li --- src/slic3r/GUI/GUI_App.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 48a278263..cb5ef7507 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -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(); - } - if (j.contains("error")) - if (!j["error"].is_null()) - error = j["error"].get(); + 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(); + } + if (j.contains("error")) { + if (!j["error"].is_null()) + error = j["error"].get(); + } + } } catch (...) {} }