Changeset - 5dd1aa90b4c0
[Not reviewed]
0 3 0
Jan Kaluza - 9 years ago 2016-02-21 19:43:39
jkaluza@redhat.com
Slack: Handle 'account_inactive' error
3 files changed with 20 insertions and 6 deletions:
0 comments (0 inline, 0 general)
include/transport/HTTPRequest.h
Show inline comments
 
@@ -18,18 +18,13 @@ class HTTPRequest : public Thread {
 
		typedef enum { Get } Type;
 
		typedef boost::function< void (HTTPRequest *, bool, rapidjson::Document &json, const std::string &data) > Callback;
 

	
 
		HTTPRequest(ThreadPool *tp, Type type, const std::string &url, Callback callback);
 
		HTTPRequest(Type type, const std::string &url);
 

	
 
		virtual ~HTTPRequest() {
 
			if(curlhandle) {
 
				curl_easy_cleanup(curlhandle);
 
				curlhandle = NULL;
 
			}
 
		}
 
		virtual ~HTTPRequest();
 

	
 
		void setProxy(std::string, std::string, std::string, std::string);
 
		bool execute();
 
		bool execute(rapidjson::Document &json);
 
		std::string getError() {return std::string(curl_errorbuffer);}
 
		const std::string &getRawData() {
libtransport/HTTPRequest.cpp
Show inline comments
 
@@ -18,12 +18,20 @@ HTTPRequest::HTTPRequest(Type type, const std::string &url) {
 
	m_url = url;
 
	m_tp = NULL;
 

	
 
	init();
 
}
 

	
 
HTTPRequest::~HTTPRequest() {
 
	if (curlhandle) {
 
		LOG4CXX_INFO(logger, "Cleaning up CURL handle");
 
		curl_easy_cleanup(curlhandle);
 
		curlhandle = NULL;
 
	}
 
}
 

	
 
bool HTTPRequest::init() {
 
	curlhandle = curl_easy_init();
 
	if (curlhandle) {
 
		curlhandle = curl_easy_init();
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXY, NULL);
 
		curl_easy_setopt(curlhandle, CURLOPT_PROXYUSERPWD, NULL);
 
@@ -82,12 +90,13 @@ bool HTTPRequest::GET(std::string url, 	std::string &data) {
 
			return true;
 
		}
 
	} else {
 
		LOG4CXX_ERROR(logger, "CURL not initialized!")
 
		strcpy(curl_errorbuffer, "CURL not initialized!");
 
	}
 
	LOG4CXX_ERROR(logger, "Error fetching " << url);
 
	return false;
 
}
 

	
 
bool HTTPRequest::GET(std::string url, rapidjson::Document &json) {
 
	if (!GET(url, m_data)) {
 
		return false;
spectrum/src/frontends/slack/SlackRTM.cpp
Show inline comments
 
@@ -185,12 +185,22 @@ void SlackRTM::handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &re
 
	if (!ok) {
 
		LOG4CXX_ERROR(logger, req->getError());
 
		LOG4CXX_ERROR(logger, data);
 
		return;
 
	}
 

	
 
	STORE_STRING_OPTIONAL(resp, error);
 
	if (!error.empty()) {
 
		if (error == "account_inactive") {
 
			LOG4CXX_INFO(logger, "Account inactive, will not try connecting again");
 
			m_pingTimer->stop();
 
			m_client->disconnectServer();
 
			return;
 
		}
 
	}
 

	
 
	rapidjson::Value &url = resp["url"];
 
	if (!url.IsString()) {
 
		LOG4CXX_ERROR(logger, "No 'url' object in the reply.");
 
		LOG4CXX_ERROR(logger, data);
 
		return;
 
	}
0 comments (0 inline, 0 general)