|
18 | 18 |
|
19 | 19 | namespace Curl |
20 | 20 | { |
| 21 | +/** |
| 22 | + * @brief Custom exception for Curl wrapper. |
| 23 | + * |
| 24 | + */ |
| 25 | +class CurlException : public std::exception |
| 26 | +{ |
| 27 | +public: |
| 28 | + /** |
| 29 | + * @brief Returns HTTP response code ID. |
| 30 | + * |
| 31 | + * @return long HTTP response code ID. |
| 32 | + */ |
| 33 | + long responseCode() const noexcept |
| 34 | + { |
| 35 | + return m_responseCode; |
| 36 | + } |
| 37 | + |
21 | 38 | /** |
22 | | - * @brief Custom exception for Curl wrapper. |
| 39 | + * @brief Returns HTTP response body. |
23 | 40 | * |
| 41 | + * @return const std::string& HTTP response body. |
24 | 42 | */ |
25 | | - class CurlException : public std::exception |
| 43 | + const std::string& responseBody() const noexcept |
26 | 44 | { |
27 | | - public: |
28 | | - /** |
29 | | - * @brief Returns HTTP response code ID. |
30 | | - * |
31 | | - * @return long HTTP response code ID. |
32 | | - */ |
33 | | - long responseCode() const noexcept |
34 | | - { |
35 | | - return m_responseCode; |
36 | | - } |
| 45 | + return m_responseBody; |
| 46 | + } |
37 | 47 |
|
38 | | - /** |
39 | | - * @brief Return error message. |
40 | | - * |
41 | | - * @return const char* Error message. |
42 | | - */ |
43 | | - const char* what() const noexcept override |
44 | | - { |
45 | | - return m_error.what(); |
46 | | - } |
| 48 | + /** |
| 49 | + * @brief Return error message. |
| 50 | + * |
| 51 | + * @return const char* Error message. |
| 52 | + */ |
| 53 | + const char* what() const noexcept override |
| 54 | + { |
| 55 | + return m_error.what(); |
| 56 | + } |
47 | 57 |
|
48 | | - /** |
49 | | - * @brief Construct a new Curl Exception object |
50 | | - * |
51 | | - * @param errorMessage Error message to show. |
52 | | - * @param responseCode HTTP response code ID. |
53 | | - */ |
54 | | - CurlException(const std::string& errorMessage, const long responseCode) |
55 | | - : m_error {errorMessage} |
56 | | - , m_responseCode {responseCode} |
57 | | - {} |
| 58 | + /** |
| 59 | + * @brief Construct a new Curl Exception object |
| 60 | + * |
| 61 | + * @param errorMessage Error message to show. |
| 62 | + * @param responseCode HTTP response code ID. |
| 63 | + * @param responseBody HTTP response body (optional). |
| 64 | + */ |
| 65 | + CurlException(const std::string& errorMessage, const long responseCode, std::string responseBody = "") |
| 66 | + : m_error {errorMessage} |
| 67 | + , m_responseCode {responseCode} |
| 68 | + , m_responseBody {std::move(responseBody)} |
| 69 | + { |
| 70 | + } |
58 | 71 |
|
59 | | - /** |
60 | | - * @brief Construct a new Curl Exception object |
61 | | - * |
62 | | - * @param curlException Pair object with an error message and a response code ID. |
63 | | - */ |
64 | | - explicit CurlException(const std::pair<const std::string&, const long>& curlException) |
65 | | - : m_error {curlException.first} |
66 | | - , m_responseCode {curlException.second} |
67 | | - {} |
| 72 | + /** |
| 73 | + * @brief Construct a new Curl Exception object |
| 74 | + * |
| 75 | + * @param curlException Pair object with an error message and a response code ID. |
| 76 | + */ |
| 77 | + explicit CurlException(const std::pair<const std::string&, const long>& curlException) |
| 78 | + : m_error {curlException.first} |
| 79 | + , m_responseCode {curlException.second} |
| 80 | + , m_responseBody {} |
| 81 | + { |
| 82 | + } |
68 | 83 |
|
69 | | - private: |
70 | | - std::runtime_error m_error; |
71 | | - const long m_responseCode; |
72 | | - }; |
73 | | -} |
| 84 | +private: |
| 85 | + std::runtime_error m_error; |
| 86 | + const long m_responseCode; |
| 87 | + const std::string m_responseBody; |
| 88 | +}; |
| 89 | +} // namespace Curl |
74 | 90 |
|
75 | 91 | #endif // _CURL_EXCEPTION_HPP |
0 commit comments