From 69fc8d805396b889b5e8c1c88e8129d93db77d29 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 20 Aug 2016 13:56:23 -0400 Subject: Updated API to use exceptions and make tweet/user objects more helpful --- src/codes.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/codes.cpp') diff --git a/src/codes.cpp b/src/codes.cpp index 9639d5d..7805c7a 100644 --- a/src/codes.cpp +++ b/src/codes.cpp @@ -1,24 +1,17 @@ #include "codes.h" +#include -std::ostream& operator<<(std::ostream& os, twitter::response r) -{ - switch (r) +namespace twitter { + + const char* invalid_response::WHAT_TEXT = "Invalid response data received from Twitter"; + const char* connection_error::WHAT_TEXT = "Error connecting to Twitter"; + + std::string unknown_error::generateMessage(int response_code) { - case twitter::response::ok: return os << "OK"; - case twitter::response::curl_error: return os << "Curl Error"; - case twitter::response::bad_auth: return os << "Bad Auth"; - case twitter::response::limited: return os << "Rate Limit Exceeded"; - case twitter::response::server_error: return os << "Twitter Server Error"; - case twitter::response::server_unavailable: return os << "Twitter Is Down"; - case twitter::response::server_overloaded: return os << "Twitter Is Over Capacity"; - case twitter::response::server_timeout: return os << "Twitter Connection Timed Out"; - case twitter::response::suspended: return os << "Authenticated User Is Suspended"; - case twitter::response::bad_token: return os << "Invalid Or Expired Access Token"; - case twitter::response::duplicate_status: return os << "Duplicate Status"; - case twitter::response::suspected_spam: return os << "Request Looks Automated"; - case twitter::response::write_restricted: return os << "Cannot Perform Write"; - case twitter::response::bad_length: return os << "Message Body Too Long"; - case twitter::response::unknown_error: return os << "Unknown Error"; - case twitter::response::invalid_media: return os << "Invalid Media"; + std::ostringstream msgbuilder; + msgbuilder << "Unknown error (HTTP " << response_code << ")"; + + return msgbuilder.str(); } -} + +}; -- cgit 1.4.1