Changeset - f0285e059882
[Not reviewed]
0 1 0
vitalyster - 12 years ago 2013-06-14 12:41:44
vitalyster@gmail.com
Twitter backend: fixed error message parsing
1 file changed with 8 insertions and 10 deletions:
0 comments (0 inline, 0 general)
backends/twitter/TwitterResponseParser.cpp
Show inline comments
 
@@ -241,27 +241,25 @@ std::vector<std::string> getIDs(std::string &json)
 

	
 
Error getErrorMessage(std::string &json)
 
{
 
	std::string error = "";
 
	std::string code = "0";
 
	Error resp;
 

	
 
	rapidjson::Document rootElement;
 
	
 
	if(rootElement.Parse<0>(json.c_str()).HasParseError()) {
 
		LOG4CXX_ERROR(logger, "Error while parsing JSON")
 
        LOG4CXX_ERROR(logger, json)
 
		return resp;
 
	}
 
		
 
	const rapidjson::Value &errorElement = rootElement[TwitterReponseTypes::error.c_str()];
 
	
 
	if(errorElement.IsArray()) {
 
		error = std::string(errorElement["message"].GetString());
 
		code = std::to_string(errorElement["code"].GetInt64());
 
	if (rootElement.IsObject()) {
 
		if (!rootElement["errors"].IsNull()) {			
 
			const rapidjson::Value &errorElement = rootElement["errors"][0u]; // first error
 
			error = std::string(errorElement["message"].GetString());
 
			code = std::to_string(errorElement["code"].GetInt64());
 
			resp.setCode(code);
 
			resp.setMessage(error);
 
		}
 
	}
 

	
 
	resp.setCode(code);
 
	resp.setMessage(error);
 

	
 
	return resp;
 
}
0 comments (0 inline, 0 general)