Added error 16: Timeout

This commit is contained in:
tastytea 2018-10-08 01:24:12 +02:00
parent f1755d8de3
commit e372614068
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6) cmake_minimum_required (VERSION 3.6)
project (mastodon-cpp project (mastodon-cpp
VERSION 0.18.6 VERSION 0.18.7
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -74,6 +74,7 @@ mastodon-cpp will never use error codes below 11, except 0.
| 13 | URL changed (HTTP 301 or 308) | | 13 | URL changed (HTTP 301 or 308) |
| 14 | Aborted by user | | 14 | Aborted by user |
| 15 | Network error (curlpp exception) | | 15 | Network error (curlpp exception) |
| 16 | Timeout |
| 100 - 999 | HTTP status codes | | 100 - 999 | HTTP status codes |
| 65535 | Unknown error | | 65535 | Unknown error |

View File

@ -147,6 +147,10 @@ const uint_fast16_t API::http::request(const method &meth,
answer = curlpp::infos::EffectiveUrl::get(request); answer = curlpp::infos::EffectiveUrl::get(request);
return 13; return 13;
} }
else if (ret == 0)
{
return 0xffff;
}
else else
{ {
return ret; return ret;
@ -154,13 +158,21 @@ const uint_fast16_t API::http::request(const method &meth,
} }
catch (curlpp::RuntimeError &e) 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. // This error is thrown if http.cancel_stream() is used.
if ((std::strncmp(e.what(), "Callback aborted", 16) == 0) || if ((what.compare(0, 16, "Callback aborted") == 0) ||
(std::strncmp(e.what(), "Failed writing body", 19) == 0)) (what.compare(0, 19, "Failed writing body") == 0))
{ {
ttdebug << "Request was cancelled by user\n"; ttdebug << "Request was cancelled by user\n";
return 14; return 14;
} }
else if (what.compare(what.size() - 20, 20, "Connection timed out") == 0)
{
ttdebug << "Timeout\n";
return 16;
}
if (parent.exceptions()) if (parent.exceptions())
{ {
@ -182,8 +194,6 @@ const uint_fast16_t API::http::request(const method &meth,
ttdebug << "curlpp::LogicError: " << e.what() << std::endl; ttdebug << "curlpp::LogicError: " << e.what() << std::endl;
return 15; return 15;
} }
return ret;
} }
const void API::http::get_headers(string &headers) const const void API::http::get_headers(string &headers) const

View File

@ -68,6 +68,7 @@ namespace Mastodon
* | 13 | URL changed (HTTP 301 or 308) | * | 13 | URL changed (HTTP 301 or 308) |
* | 14 | Cancelled by user | * | 14 | Cancelled by user |
* | 15 | Network error (curlpp exception) | * | 15 | Network error (curlpp exception) |
* | 16 | Timeout |
* | 100 - 999 | HTTP status codes | * | 100 - 999 | HTTP status codes |
* | 65535 | Unknown error | * | 65535 | Unknown error |
* *