]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
radosgw-admin: parse error messages from failed requests
authorCasey Bodley <cbodley@redhat.com>
Fri, 18 Mar 2016 20:56:24 +0000 (16:56 -0400)
committerCasey Bodley <cbodley@redhat.com>
Wed, 23 Mar 2016 15:25:21 +0000 (11:25 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/rgw/rgw_admin.cc

index 0bb5570162fac177c5539febae1a4d7a9b3eae63..29967ddb543ce2dbabc70b98f80eb842ab9ad5ef 100644 (file)
@@ -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;
   }