diff --git a/include/exceptions.hpp b/include/exceptions.hpp index 9e51d97..5cbad42 100644 --- a/include/exceptions.hpp +++ b/include/exceptions.hpp @@ -55,6 +55,13 @@ public: explicit CURLException(const CURLcode &error, string message, string error_buffer); + /*! + * @brief Constructor with message. + * + * @since 0.1.0 + */ + explicit CURLException(string message); + /*! * @brief The error code returned by libcurl. * diff --git a/src/exceptions.cpp b/src/exceptions.cpp index 7dd0e0f..f4630a4 100644 --- a/src/exceptions.cpp +++ b/src/exceptions.cpp @@ -36,10 +36,19 @@ CURLException::CURLException(const CURLcode &error, string message, , _error_buffer{move(error_buffer)} {} +CURLException::CURLException(string message) + : error_code{CURLE_OK} + , _message{move(message)} +{} + const char *CURLException::what() const noexcept { - static string error_string{"libCURL error: " + to_string(error_code) - + " - " + _message}; + static string error_string{"libCURL error: "}; + if (error_code != CURLE_OK) + { + error_string += to_string(error_code) + " - "; + } + error_string += _message; if (!_error_buffer.empty()) { error_string += " [" + _error_buffer + "]";