Skip to content

Commit

Permalink
Process the json file received
Browse files Browse the repository at this point in the history
Instead of returning a HTML it receives the json file and process.
It is easier to parse and get the information on exceptions.

re #6176
  • Loading branch information
gesnerpassos committed Apr 22, 2013
1 parent c048cb9 commit 3efa335
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -761,15 +761,19 @@ namespace API
<< response.getStatus() << " " << response.getReason() << std::endl;
std::stringstream answer;
Poco::StreamCopier::copyStream(rs, answer);
std::string html_answer = answer.str();
g_log.information() << "FormOutput: " << answer.str() << std::endl;
size_t pos1, pos2;
pos1 = html_answer.find("<body>");
pos2 = html_answer.find("</body>");
if (pos1 != std::string::npos && pos2 != std::string::npos){
throw ScriptRepoException(std::string(html_answer.begin()+pos1, html_answer.begin()+pos2+1));
g_log.debug() << "Form Output: " << answer.str() << std::endl;

ptree pt;
try{
read_json(answer, pt);
std::string info = pt.get<std::string>("message","");
std::string detail = pt.get<std::string>("detail","");
throw ScriptRepoException(info, detail);

}catch (boost::property_tree::json_parser_error & ex){
throw ScriptRepoException("Bad answer from the Server",
ex.what());
}

}
}catch(Poco::Exception & ex){
throw ScriptRepoException(ex.displayText(), ex.className());
Expand Down

0 comments on commit 3efa335

Please sign in to comment.