aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/httpclient.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-08-21 12:55:51 +0200
committerGitHub <[email protected]>2023-08-21 12:55:51 +0200
commitd2ca9955853a4c49a0c780b2790814368d3de8a6 (patch)
tree19f3cf4f8a69ca8724f39d7123f8c83b77135293 /src/zenhttp/httpclient.cpp
parentfix trace close (#365) (diff)
downloadzen-d2ca9955853a4c49a0c780b2790814368d3de8a6.tar.xz
zen-d2ca9955853a4c49a0c780b2790814368d3de8a6.zip
oplog mirror support (#367)
feature: added oplog-mirror command. this can be invoked to export oplog contents to corresponding files
Diffstat (limited to 'src/zenhttp/httpclient.cpp')
-rw-r--r--src/zenhttp/httpclient.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp
index 05ff6d07b..744787201 100644
--- a/src/zenhttp/httpclient.cpp
+++ b/src/zenhttp/httpclient.cpp
@@ -435,7 +435,28 @@ HttpClient::Response::ToText()
bool
HttpClient::Response::IsSuccess() const noexcept
{
- return IsHttpSuccessCode(StatusCode);
+ return !Error && IsHttpSuccessCode(StatusCode);
+}
+
+void
+HttpClient::Response::ThrowError(std::string_view ErrorPrefix)
+{
+ if (!IsSuccess())
+ {
+ if (Error.has_value())
+ {
+ throw std::runtime_error(fmt::format("{}: {}", ErrorPrefix, Error->ErrorMessage));
+ }
+ else if (StatusCode != HttpResponseCode::ImATeapot && (int)StatusCode)
+ {
+ throw std::runtime_error(
+ fmt::format("{}: HTTP error {} {} ({})", ErrorPrefix, (int)StatusCode, zen::ToString(StatusCode), AsText()));
+ }
+ else
+ {
+ throw std::runtime_error(fmt::format("{}: {}", ErrorPrefix, "unknown error"));
+ }
+ }
}
//////////////////////////////////////////////////////////////////////////