Incremented all error codes by 10

This commit is contained in:
tastytea 2018-02-28 22:37:30 +01:00
parent e6b5869ca8
commit a7c96cf30e
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
19 changed files with 65 additions and 65 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastodon-cpp
VERSION 0.4.5
VERSION 0.5.0
LANGUAGES CXX
)

View File

@ -69,25 +69,21 @@ After you did a `make install`, a project consisting of one file can be compiled
## Error codes
mastodon-cpp will never use error codes below 11, except 0.
| Code | Explanation |
| --------: |:------------------------------|
| 0 | No error |
| 1 | Invalid call |
| 2 | Not implemented |
| 3 | URL changed (HTTP 301 or 308) |
| 4 | Aborted by user |
| 10 | Failed to connect |
| 11 | Couldn't resolve host |
| 12 | Network is unreachable |
| 11 | Invalid call |
| 12 | Not implemented |
| 13 | URL changed (HTTP 301 or 308) |
| 14 | Aborted by user |
| 20 | Failed to connect |
| 21 | Couldn't resolve host |
| 22 | Network is unreachable |
| 100 - 999 | HTTP status codes |
| 65535 | Unknown error |
| | Deprecated (since 0.2.10) |
| --------: |:------------------------------|
| 16 | Connection failed |
| 17 | TLS error |
| 18 | Invalid response from server |
If you use a debug build, you get more verbose error messages.
## Useful links

View File

@ -36,7 +36,7 @@ const std::uint16_t API::del(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}
@ -71,7 +71,7 @@ const std::uint16_t API::del(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}

View File

@ -79,7 +79,7 @@ const std::uint16_t API::get(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}
@ -166,7 +166,7 @@ const std::uint16_t API::get(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}

View File

@ -42,7 +42,7 @@ const std::uint16_t API::get_stream(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}
@ -69,7 +69,7 @@ const std::uint16_t API::get_stream(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}

View File

@ -35,7 +35,7 @@ const std::uint16_t API::patch(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}

View File

@ -66,7 +66,7 @@ const std::uint16_t API::post(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}
@ -142,7 +142,7 @@ const std::uint16_t API::post(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}

View File

@ -38,7 +38,7 @@ const std::uint16_t API::put(const Mastodon::API::v1 &call,
break;
default:
ttdebug << "ERROR: Invalid call.\n";
return 1;
return 11;
break;
}

View File

@ -68,7 +68,7 @@ int main(int argc, char *argv[])
return ret;
}
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -56,7 +56,7 @@ int main(int argc, char *argv[])
}
}
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -104,7 +104,7 @@ int main(int argc, char *argv[])
pt::write_json(filename, config);
}
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -63,7 +63,7 @@ int main(int argc, char *argv[])
{
std::cout << answer << '\n';
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -37,7 +37,7 @@ int main(int argc, char *argv[])
{
// std::cout << answer << '\n';
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -54,7 +54,7 @@ int main(int argc, char *argv[])
return ret;
}
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -72,7 +72,7 @@ int main(int argc, char *argv[])
return ret;
}
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << url << '\n';

View File

@ -37,7 +37,7 @@ int main(int argc, char *argv[])
std::cout << "🔥 Please let the server cool off a bit! 🔥\n";
}
}
else if (ret == 3)
else if (ret == 13)
{
std::cerr << "The URL has permanently changed.\n" <<
"New URL: " << answer << '\n';

View File

@ -71,6 +71,7 @@ const std::uint16_t API::http::request_sync(const method &meth,
std::list<string> headers;
request.setOpt<curlopts::Url>("https://" + _instance + path);
ttdebug << "User-Agent: " << parent.get_useragent() << "\n";
request.setOpt<curlopts::UserAgent>(parent.get_useragent());
headers.push_back("Connection: close");
@ -127,7 +128,7 @@ const std::uint16_t API::http::request_sync(const method &meth,
{ // Moved Permanently or Permanent Redirect
// return new URL
answer = curlpp::infos::EffectiveUrl::get(request);
return 3;
return 13;
}
else
{
@ -140,22 +141,24 @@ const std::uint16_t API::http::request_sync(const method &meth,
"Failed writing body", 19) == 0)
{
ttdebug << "Request was aborted by user\n";
return 4;
return 14;
}
else if (std::strncmp(e.what(),
"Failed to connect to", 20) == 0)
{
ret = 10;
ret = 20;
}
else if (std::strncmp(e.what(),
"Couldn't resolve host", 21) == 0)
"Couldn't resolve host", 21) == 0 ||
std::strncmp(e.what(),
"Could not resolve host", 22) == 0)
{
ret = 11;
ret = 21;
}
else if (std::strncmp(e.what(),
"Network is unreachable", 22) == 0)
{
ret = 12;
ret = 22;
}
else
{

View File

@ -184,7 +184,7 @@ const std::uint16_t API::register_app1(const string &client_name,
return 0;
}
else if (ret == 3)
else if (ret == 13)
{
url = answer;
return ret;

View File

@ -42,16 +42,17 @@ namespace Mastodon
* @brief Class for the Mastodon API. All input is expected to be UTF-8.
* Binary data must be base64-encoded or a filename.
* @section error Error codes
* mastodon-cpp will never use error codes below 11, except 0.
* | Code | Explanation |
* | --------: |:------------------------------|
* | 0 | No error |
* | 1 | Invalid call |
* | 2 | Not implemented |
* | 3 | URL changed (HTTP 301 or 308) |
* | 4 | Aborted by user |
* | 10 | Failed to connect |
* | 11 | Couldn't resolve host |
* | 12 | Network is unreachable |
* | 11 | Invalid call |
* | 12 | Not implemented |
* | 13 | URL changed (HTTP 301 or 308) |
* | 14 | Aborted by user |
* | 20 | Failed to connect |
* | 21 | Couldn't resolve host |
* | 22 | Network is unreachable |
* | 100 - 999 | HTTP status codes |
* | 65535 | Unknown exception |
*/
@ -91,8 +92,8 @@ public:
* @param formdata The form data for PATCH and POST request.
* @param answer The answer from the server
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* is returned and answer is set to the new URL.
* @return @ref error "Error code". If the URL has permanently changed,
* 13 is returned and answer is set to the new URL.
*/
const std::uint16_t request_sync(const method &meth,
const std::string &path,
@ -261,7 +262,7 @@ public:
* @param client_secret Returned
* @param url Returned, used to generate code for register_app2
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and url is set to the new URL.
*/
const std::uint16_t register_app1(const std::string &client_name,
@ -332,7 +333,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error an
* empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get(const Mastodon::API::v1 &call,
@ -348,7 +349,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get(const Mastodon::API::v1 &call,
@ -364,7 +365,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get(const Mastodon::API::v1 &call,
@ -379,7 +380,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error an
* empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get(const std::string &call,
@ -395,7 +396,7 @@ public:
* @param ptr Pointer to the http object. Can be used to call
* ptr->abort_stream()
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get_stream(const Mastodon::API::v1 &call,
@ -412,7 +413,7 @@ public:
* @param ptr Pointer to the http object. Can be used to call
* ptr->abort_stream()
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get_stream(const Mastodon::API::v1 &call,
@ -428,7 +429,7 @@ public:
* @param ptr Pointer to the http object. Can be used to call
* ptr->abort_stream()
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t get_stream(const std::string &call,
@ -445,7 +446,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t patch(const Mastodon::API::v1 &call,
@ -459,7 +460,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error an
* empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t post(const Mastodon::API::v1 &call,
@ -473,7 +474,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error an
* empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t post(const Mastodon::API::v1 &call,
@ -491,7 +492,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t post(const Mastodon::API::v1 &call,
@ -509,7 +510,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t post(const Mastodon::API::v1 &call,
@ -527,7 +528,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t post(const std::string &call,
@ -544,7 +545,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t put(const Mastodon::API::v1 &call,
@ -561,7 +562,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t put(const std::string &call,
@ -613,7 +614,7 @@ public:
* @param answer The answer from the server. Usually JSON. On error
* an empty string.
*
* @return @ref error "Error code". If the URL has permanently changed, 3
* @return @ref error "Error code". If the URL has permanently changed, 13
* is returned and answer is set to the new URL.
*/
const std::uint16_t del(const std::string &call,