From 292d8967d46ccf62f1d4c996c5466548b5b05501 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 18 Mar 2016 16:56:24 -0400 Subject: [PATCH] radosgw-admin: parse error messages from failed requests Signed-off-by: Casey Bodley --- src/rgw/rgw_admin.cc | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 0bb5570162fac..29967ddb543ce 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -1316,15 +1316,13 @@ static int send_to_remote_gateway(const string& remote, req_info& info, } rgw_user user; int ret = conn->forward(user, info, NULL, MAX_REST_RESPONSE, &in_data, &response); - if (ret < 0) { - return ret; - } - ret = parser.parse(response.c_str(), response.length()); - if (ret < 0) { + + int parse_ret = parser.parse(response.c_str(), response.length()); + if (parse_ret < 0) { cerr << "failed to parse response" << std::endl; - return ret; + return parse_ret; } - return 0; + return ret; } static int send_to_url(const string& url, RGWAccessKey& key, req_info& info, @@ -1335,15 +1333,13 @@ static int send_to_url(const string& url, RGWAccessKey& key, req_info& info, bufferlist response; int ret = req.forward_request(key, info, MAX_REST_RESPONSE, &in_data, &response); - if (ret < 0) { - return ret; - } - ret = parser.parse(response.c_str(), response.length()); - if (ret < 0) { + + int parse_ret = parser.parse(response.c_str(), response.length()); + if (parse_ret < 0) { cout << "failed to parse response" << std::endl; - return ret; + return parse_ret; } - return 0; + return ret; } static int send_to_remote_or_url(const string& remote, const string& url, @@ -1410,6 +1406,12 @@ static int commit_period(RGWRealm& realm, RGWPeriod& period, int ret = send_to_remote_or_url(remote, url, access, secret, info, bl, p); if (ret < 0) { cerr << "request failed: " << cpp_strerror(-ret) << std::endl; + + // did we parse an error message? + auto message = p.find_obj("Message"); + if (message) { + cerr << "Reason: " << message->get_data() << std::endl; + } return ret; } -- 2.39.5