Fix CURLException::what().

This commit is contained in:
tastytea 2020-11-13 20:28:24 +01:00
parent 442f27a511
commit e1827d08cc
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 11 additions and 7 deletions

View File

@ -222,15 +222,19 @@ void CURLWrapper::check(const CURLcode code)
}
}
const char *CURLException::what() noexcept
const char *CURLException::what() const noexcept
{
if (!_error_message.empty())
// NOTE: The string has to be static, or it'll vanish before it can be
// used. Couldn't find good documentation on that.
static string error_string;
error_string = _error_message;
if (!error_string.empty())
{
_error_message = ": " + _error_message;
error_string = " " + error_string;
}
_error_message = "libcurl_error: " + std::to_string(error_code)
+ _error_message;
return _error_message.c_str();
error_string = "libcurl error: " + std::to_string(error_code)
+ error_string;
return error_string.c_str();
}
} // namespace curl_wrapper

View File

@ -233,7 +233,7 @@ public:
*
* @since 0.1.0
*/
[[nodiscard]] const char *what() noexcept;
[[nodiscard]] const char *what() const noexcept override;
private:
string _error_message;