Skip to content

Commit

Permalink
Send to connect: trying to extract server error message for nicer err…
Browse files Browse the repository at this point in the history
…or dialog
  • Loading branch information
barzto authored and lukasmatena committed Jun 27, 2024
1 parent 510bb20 commit 0131b30
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/slic3r/Utils/PrusaConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ std::string escape_path_by_element(const boost::filesystem::path& path)
}
return ret_val;
}

boost::optional<std::string> get_error_message_from_response_body(const std::string& body)
{
boost::optional<std::string> message;
std::stringstream ss(body);
pt::ptree ptree;
try
{
pt::read_json(ss, ptree);
message = ptree.get_optional<std::string>("message");
}
// ignore possible errors if body is not valid JSON
catch (std::exception&)
{}

return message;
}

}

PrusaConnectNew::PrusaConnectNew(DynamicPrintConfig *config)
Expand Down Expand Up @@ -125,7 +143,9 @@ bool PrusaConnectNew::init_upload(PrintHostUpload upload_data, std::string& out)
BOOST_LOG_TRIVIAL(error) << body;
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error registering file: %2%, HTTP %3%, body: `%4%`") % name % error % status % body;
res = false;
out = GUI::into_u8(format_error(body, error, status));
out = get_error_message_from_response_body(body).value_or_eval([&](){
return GUI::into_u8(format_error(body, error, status));
});
})
.perform_sync();
return res;
Expand Down

0 comments on commit 0131b30

Please sign in to comment.