From e372614068f1fef6fa32b4d91fe006f9bc8d5197 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 8 Oct 2018 01:24:12 +0200 Subject: [PATCH] Added error 16: Timeout --- CMakeLists.txt | 2 +- README.md | 1 + src/http.cpp | 18 ++++++++++++++---- src/mastodon-cpp.hpp | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bd0c06..96abfcc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.6) project (mastodon-cpp - VERSION 0.18.6 + VERSION 0.18.7 LANGUAGES CXX ) diff --git a/README.md b/README.md index 4ddbfd3..c8226a7 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ mastodon-cpp will never use error codes below 11, except 0. | 13 | URL changed (HTTP 301 or 308) | | 14 | Aborted by user | | 15 | Network error (curlpp exception) | +| 16 | Timeout | | 100 - 999 | HTTP status codes | | 65535 | Unknown error | diff --git a/src/http.cpp b/src/http.cpp index f11bb2b..38aee4c 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -147,6 +147,10 @@ const uint_fast16_t API::http::request(const method &meth, answer = curlpp::infos::EffectiveUrl::get(request); return 13; } + else if (ret == 0) + { + return 0xffff; + } else { return ret; @@ -154,13 +158,21 @@ const uint_fast16_t API::http::request(const method &meth, } catch (curlpp::RuntimeError &e) { + const string what = e.what(); + ttdebug << what.compare(what.size() - 20, 20, "Connection timed out") << '\n'; + ttdebug << what.substr(what.size() - 20, 20) << '\n'; // This error is thrown if http.cancel_stream() is used. - if ((std::strncmp(e.what(), "Callback aborted", 16) == 0) || - (std::strncmp(e.what(), "Failed writing body", 19) == 0)) + if ((what.compare(0, 16, "Callback aborted") == 0) || + (what.compare(0, 19, "Failed writing body") == 0)) { ttdebug << "Request was cancelled by user\n"; return 14; } + else if (what.compare(what.size() - 20, 20, "Connection timed out") == 0) + { + ttdebug << "Timeout\n"; + return 16; + } if (parent.exceptions()) { @@ -182,8 +194,6 @@ const uint_fast16_t API::http::request(const method &meth, ttdebug << "curlpp::LogicError: " << e.what() << std::endl; return 15; } - - return ret; } const void API::http::get_headers(string &headers) const diff --git a/src/mastodon-cpp.hpp b/src/mastodon-cpp.hpp index 023fede..27294fa 100644 --- a/src/mastodon-cpp.hpp +++ b/src/mastodon-cpp.hpp @@ -68,6 +68,7 @@ namespace Mastodon * | 13 | URL changed (HTTP 301 or 308) | * | 14 | Cancelled by user | * | 15 | Network error (curlpp exception) | + * | 16 | Timeout | * | 100 - 999 | HTTP status codes | * | 65535 | Unknown error | *