Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tried to print error in savebackup #57

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/controllerclientimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,14 @@ int ControllerClientImpl::_CallGet(const std::string& desturi, std::string& outp
return http_code;
}

int ControllerClientImpl::_DuplicateStreamCallback(char *data, size_t size, size_t nmemb, void **writerDataStringStreamAndOStream)
{
if(((std::stringstream*)writerDataStringStreamAndOStream[0])->tellp() < 0x1000) {
ControllerClientImpl::_WriteStringStreamCallback(data, size, nmemb, (std::stringstream*)writerDataStringStreamAndOStream[0]);
}
return ControllerClientImpl::_WriteOStreamCallback(data, size, nmemb, (std::ostream*)writerDataStringStreamAndOStream[1]);
}

int ControllerClientImpl::CallGet(const std::string& relativeuri, std::ostream& outputStream, int expectedhttpcode, double timeout)
{
boost::mutex::scoped_lock lock(_mutex);
Expand All @@ -614,15 +622,25 @@ int ControllerClientImpl::_CallGet(const std::string& desturi, std::ostream& out
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_TIMEOUT_MS, 0L, (long)(timeout * 1000L));
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_HTTPHEADER, NULL, _httpheadersjson);
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_URL, NULL, desturi.c_str());
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_WRITEFUNCTION, NULL, _WriteOStreamCallback);
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_WRITEDATA, NULL, &outputStream);
_buffer.clear();
_buffer.str("");
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_WRITEFUNCTION, NULL, _DuplicateStreamCallback);
void *writerData[]={&_buffer,&outputStream};
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_WRITEDATA, NULL, writerData);
CURL_OPTION_SAVE_SETTER(_curl, CURLOPT_HTTPGET, 0L, 1L);
CURL_PERFORM(_curl);
long http_code = 0;
CURL_INFO_GETTER(_curl, CURLINFO_RESPONSE_CODE, &http_code);
std::string outputdata = _buffer.str();
if( expectedhttpcode != 0 && http_code != expectedhttpcode ) {
// outputStream is not always seekable; ignore any error message.
throw MUJIN_EXCEPTION_FORMAT("HTTP GET to '%s' returned HTTP status %s (outputStream might have information)", desturi%http_code, MEC_HTTPServer);
if( outputdata.size() > 0 ) {
rapidjson::Document d;
ParseJson(d, _buffer.str());
cielavenir marked this conversation as resolved.
Show resolved Hide resolved
std::string error_message = GetJsonValueByKey<std::string>(d, "error_message");
std::string traceback = GetJsonValueByKey<std::string>(d, "traceback");
throw MUJIN_EXCEPTION_FORMAT("HTTP GET to '%s' returned HTTP status %s: %s", desturi%http_code%error_message, MEC_HTTPServer);
}
throw MUJIN_EXCEPTION_FORMAT("HTTP GET to '%s' returned HTTP status %s", desturi%http_code, MEC_HTTPServer);
}
return http_code;
}
Expand Down
1 change: 1 addition & 0 deletions src/controllerclientimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class ControllerClientImpl : public ControllerClient, public boost::enable_share
static int _WriteVectorCallback(char *data, size_t size, size_t nmemb, std::vector<unsigned char> *writerData);
static int _WriteOStreamCallback(char *data, size_t size, size_t nmemb, std::ostream *writerData);
static int _ReadIStreamCallback(char *data, size_t size, size_t nmemb, std::istream *writerData);
static int _DuplicateStreamCallback(char *data, size_t size, size_t nmemb, void **writerDataStringStreamAndOStream);

/// \brief sets up http header for doing http operation with json data
void _SetupHTTPHeadersJSON();
Expand Down