diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-08-20 13:56:23 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-08-20 13:56:23 -0400 |
| commit | 69fc8d805396b889b5e8c1c88e8129d93db77d29 (patch) | |
| tree | 6b807bd9332c65b65066e247d4d00fd5e4118d2e /src/codes.h | |
| parent | 442f1ee071152be04c4184473ddfee5040795b76 (diff) | |
| download | libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.tar.gz libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.tar.bz2 libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.zip | |
Updated API to use exceptions and make tweet/user objects more helpful
Diffstat (limited to 'src/codes.h')
| -rw-r--r-- | src/codes.h | 193 |
1 files changed, 172 insertions, 21 deletions
| diff --git a/src/codes.h b/src/codes.h index 6767805..baf4f8f 100644 --- a/src/codes.h +++ b/src/codes.h | |||
| @@ -1,32 +1,183 @@ | |||
| 1 | #ifndef CODES_H_05838D39 | 1 | #ifndef CODES_H_05838D39 |
| 2 | #define CODES_H_05838D39 | 2 | #define CODES_H_05838D39 |
| 3 | 3 | ||
| 4 | #include <ostream> | 4 | #include <stdexcept> |
| 5 | #include <string> | ||
| 5 | 6 | ||
| 6 | namespace twitter { | 7 | namespace twitter { |
| 7 | 8 | ||
| 8 | enum class response { | 9 | class twitter_error : public std::runtime_error { |
| 9 | ok, | 10 | public: |
| 10 | curl_error, | 11 | |
| 11 | bad_auth, | 12 | using std::runtime_error::runtime_error; |
| 12 | limited, | 13 | }; |
| 13 | server_error, | 14 | |
| 14 | server_unavailable, | 15 | class bad_auth : public twitter_error { |
| 15 | server_overloaded, | 16 | public: |
| 16 | server_timeout, | 17 | |
| 17 | suspended, | 18 | using twitter_error::twitter_error; |
| 18 | bad_token, | 19 | }; |
| 19 | duplicate_status, | 20 | |
| 20 | suspected_spam, | 21 | class invalid_response : public twitter_error { |
| 21 | write_restricted, | 22 | public: |
| 22 | bad_length, | 23 | |
| 23 | unknown_error, | 24 | static const char* WHAT_TEXT; |
| 24 | invalid_media, | 25 | |
| 25 | invalid_response | 26 | explicit invalid_response(std::string response) noexcept |
| 27 | : twitter_error(WHAT_TEXT), _response(std::move(response)) | ||
| 28 | { | ||
| 29 | } | ||
| 30 | |||
| 31 | const std::string& getResponse() const noexcept | ||
| 32 | { | ||
| 33 | return _response; | ||
| 34 | } | ||
| 35 | |||
| 36 | private: | ||
| 37 | |||
| 38 | std::string _response; | ||
| 39 | }; | ||
| 40 | |||
| 41 | class account_suspended : public twitter_error { | ||
| 42 | public: | ||
| 43 | |||
| 44 | using twitter_error::twitter_error; | ||
| 45 | }; | ||
| 46 | |||
| 47 | class rate_limit_exceeded : public twitter_error { | ||
| 48 | public: | ||
| 49 | |||
| 50 | using twitter_error::twitter_error; | ||
| 51 | }; | ||
| 52 | |||
| 53 | class update_limit_exceeded : public twitter_error { | ||
| 54 | public: | ||
| 55 | |||
| 56 | using twitter_error::twitter_error; | ||
| 57 | }; | ||
| 58 | |||
| 59 | class bad_token : public twitter_error { | ||
| 60 | public: | ||
| 61 | |||
| 62 | using twitter_error::twitter_error; | ||
| 63 | }; | ||
| 64 | |||
| 65 | class server_overloaded : public twitter_error { | ||
| 66 | public: | ||
| 67 | |||
| 68 | using twitter_error::twitter_error; | ||
| 69 | }; | ||
| 70 | |||
| 71 | class server_error : public twitter_error { | ||
| 72 | public: | ||
| 73 | |||
| 74 | using twitter_error::twitter_error; | ||
| 75 | }; | ||
| 76 | |||
| 77 | class bad_length : public twitter_error { | ||
| 78 | public: | ||
| 79 | |||
| 80 | using twitter_error::twitter_error; | ||
| 81 | }; | ||
| 82 | |||
| 83 | class duplicate_status : public twitter_error { | ||
| 84 | public: | ||
| 85 | |||
| 86 | using twitter_error::twitter_error; | ||
| 87 | }; | ||
| 88 | |||
| 89 | class suspected_spam : public twitter_error { | ||
| 90 | public: | ||
| 91 | |||
| 92 | using twitter_error::twitter_error; | ||
| 93 | }; | ||
| 94 | |||
| 95 | class write_restricted : public twitter_error { | ||
| 96 | public: | ||
| 97 | |||
| 98 | using twitter_error::twitter_error; | ||
| 99 | }; | ||
| 100 | |||
| 101 | class invalid_media : public twitter_error { | ||
| 102 | public: | ||
| 103 | |||
| 104 | using twitter_error::twitter_error; | ||
| 105 | }; | ||
| 106 | |||
| 107 | class server_unavailable : public twitter_error { | ||
| 108 | public: | ||
| 109 | |||
| 110 | using twitter_error::twitter_error; | ||
| 111 | }; | ||
| 112 | |||
| 113 | class server_timeout : public twitter_error { | ||
| 114 | public: | ||
| 115 | |||
| 116 | using twitter_error::twitter_error; | ||
| 117 | }; | ||
| 118 | |||
| 119 | class unknown_error : public twitter_error { | ||
| 120 | public: | ||
| 121 | |||
| 122 | unknown_error(int response_code, std::string response_data) | ||
| 123 | : twitter_error(generateMessage(response_code)), | ||
| 124 | _response_code(response_code), | ||
| 125 | _response_data(std::move(response_data)) | ||
| 126 | { | ||
| 127 | } | ||
| 128 | |||
| 129 | int getResponseCode() const noexcept | ||
| 130 | { | ||
| 131 | return _response_code; | ||
| 132 | } | ||
| 133 | |||
| 134 | const std::string& getResponse() const noexcept | ||
| 135 | { | ||
| 136 | return _response_data; | ||
| 137 | } | ||
| 138 | |||
| 139 | private: | ||
| 140 | |||
| 141 | static std::string generateMessage(int response_code); | ||
| 142 | |||
| 143 | int _response_code; | ||
| 144 | std::string _response_data; | ||
| 145 | }; | ||
| 146 | |||
| 147 | class connection_error : public twitter_error { | ||
| 148 | public: | ||
| 149 | |||
| 150 | static const char* WHAT_TEXT; | ||
| 151 | |||
| 152 | connection_error() noexcept : twitter_error(WHAT_TEXT) | ||
| 153 | { | ||
| 154 | } | ||
| 155 | }; | ||
| 156 | |||
| 157 | class invalid_member : public std::domain_error { | ||
| 158 | public: | ||
| 159 | |||
| 160 | using std::domain_error::domain_error; | ||
| 161 | }; | ||
| 162 | |||
| 163 | class malformed_object : public invalid_response { | ||
| 164 | public: | ||
| 165 | |||
| 166 | malformed_object(std::string type, std::string data) noexcept | ||
| 167 | : invalid_response(std::move(data)), _type(std::move(type)) | ||
| 168 | { | ||
| 169 | } | ||
| 170 | |||
| 171 | const std::string& getType() const noexcept | ||
| 172 | { | ||
| 173 | return _type; | ||
| 174 | } | ||
| 175 | |||
| 176 | private: | ||
| 177 | |||
| 178 | std::string _type; | ||
| 26 | }; | 179 | }; |
| 27 | 180 | ||
| 28 | }; | 181 | }; |
| 29 | 182 | ||
| 30 | std::ostream& operator<<(std::ostream& os, twitter::response r); | ||
| 31 | |||
| 32 | #endif /* end of include guard: CODES_H_05838D39 */ | 183 | #endif /* end of include guard: CODES_H_05838D39 */ |
