From 5dd1aa90b4c0f77bd0e0fb77bef15d59318e3510 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Sun, 21 Feb 2016 19:43:39 +0100 Subject: [PATCH] Slack: Handle 'account_inactive' error --- include/transport/HTTPRequest.h | 7 +------ libtransport/HTTPRequest.cpp | 9 +++++++++ spectrum/src/frontends/slack/SlackRTM.cpp | 10 ++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/transport/HTTPRequest.h b/include/transport/HTTPRequest.h index c3b25b7b..d1b780e8 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 e63bf0ef..d9b30bdb 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 493dd70a..69da3986 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.");