aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenhttp')
-rw-r--r--src/zenhttp/httpclient.cpp7
-rw-r--r--src/zenhttp/include/zenhttp/httpclient.h23
2 files changed, 27 insertions, 3 deletions
diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp
index a2d323b5e..30a2bfc65 100644
--- a/src/zenhttp/httpclient.cpp
+++ b/src/zenhttp/httpclient.cpp
@@ -1628,12 +1628,13 @@ HttpClient::Response::ErrorMessage(std::string_view Prefix) const
}
else if (StatusCode != HttpResponseCode::ImATeapot && (int)StatusCode)
{
- return fmt::format("{}{}HTTP error {} {} ({})",
+ std::string TextResponse = ToText();
+ return fmt::format("{}{}HTTP error {} {}{}",
Prefix,
Prefix.empty() ? ""sv : ": "sv,
(int)StatusCode,
zen::ToString(StatusCode),
- ToText());
+ TextResponse.empty() ? ""sv : fmt::format(" ({})", TextResponse));
}
else
{
@@ -1646,7 +1647,7 @@ HttpClient::Response::ThrowError(std::string_view ErrorPrefix)
{
if (!IsSuccess())
{
- throw std::runtime_error(ErrorMessage(ErrorPrefix));
+ throw HttpClientError(ErrorMessage(ErrorPrefix), Error.has_value() ? Error.value().ErrorCode : 0, StatusCode);
}
}
diff --git a/src/zenhttp/include/zenhttp/httpclient.h b/src/zenhttp/include/zenhttp/httpclient.h
index c991a71ea..50bd5b53a 100644
--- a/src/zenhttp/include/zenhttp/httpclient.h
+++ b/src/zenhttp/include/zenhttp/httpclient.h
@@ -57,6 +57,29 @@ struct HttpClientSettings
uint8_t RetryCount = 0;
};
+class HttpClientError : public std::runtime_error
+{
+public:
+ using _Mybase = runtime_error;
+
+ HttpClientError(const std::string& Message, int Error, HttpResponseCode ResponseCode)
+ : _Mybase(Message)
+ , m_Error(Error)
+ , m_ResponseCode(ResponseCode)
+ {
+ }
+
+ HttpClientError(const char* Message, int Error, HttpResponseCode ResponseCode)
+ : _Mybase(Message)
+ , m_Error(Error)
+ , m_ResponseCode(ResponseCode)
+ {
+ }
+
+ const int m_Error = 0;
+ const HttpResponseCode m_ResponseCode = HttpResponseCode::ImATeapot;
+};
+
class HttpClient
{
public: