From 5dd1aa90b4c0f77bd0e0fb77bef15d59318e3510 2016-02-21 19:43:39 From: Jan Kaluza Date: 2016-02-21 19:43:39 Subject: [PATCH] Slack: Handle 'account_inactive' error --- diff --git a/include/transport/HTTPRequest.h b/include/transport/HTTPRequest.h index c3b25b7bd8886252ebcf154b779e6b464e18b577..d1b780e86cce43a03f87768b5dfa6471f52458a1 100644 --- a/include/transport/HTTPRequest.h +++ b/include/transport/HTTPRequest.h @@ -21,12 +21,7 @@ class HTTPRequest : public Thread { 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(); diff --git a/libtransport/HTTPRequest.cpp b/libtransport/HTTPRequest.cpp index e63bf0ef206805790ecd6ef3c06f3596a98a7abf..d9b30bdbd686752c4d1f777292b6bcbb4ccb61a2 100644 --- a/libtransport/HTTPRequest.cpp +++ b/libtransport/HTTPRequest.cpp @@ -21,6 +21,14 @@ HTTPRequest::HTTPRequest(Type type, const std::string &url) { 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) { @@ -85,6 +93,7 @@ bool HTTPRequest::GET(std::string url, std::string &data) { LOG4CXX_ERROR(logger, "CURL not initialized!") strcpy(curl_errorbuffer, "CURL not initialized!"); } + LOG4CXX_ERROR(logger, "Error fetching " << url); return false; } diff --git a/spectrum/src/frontends/slack/SlackRTM.cpp b/spectrum/src/frontends/slack/SlackRTM.cpp index 493dd70a1a504cfdd6fbda4fe30c1dd2ab0371fc..69da3986f28ce9b36dc7d682a716a48c015f08df 100644 --- a/spectrum/src/frontends/slack/SlackRTM.cpp +++ b/spectrum/src/frontends/slack/SlackRTM.cpp @@ -188,6 +188,16 @@ void SlackRTM::handleRTMStart(HTTPRequest *req, bool ok, rapidjson::Document &re 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.");