buffet: Pass error from GCD if available. This helps when e.g. the passed registration ticket is not found: # buffet_client RegisterDevice "ticket_id=bogus&client_secret=REDACTED&api_key=REDACTED&oauth_url=https://accounts.google.com/o/oauth2/&service_url=https://www.googleapis.com/clouddevices/v1/" [0212/152521:ERROR:logging.h(777)] Failed to call method: org.chromium.Buffet.Manager.RegisterDevice: object_path= /org/chromium/Buffet/Manager: org.freedesktop.DBus.Error.Failed: gcd_server/notFound:Registration ticket not found [0212/152521:ERROR:dbus_method_invoker.h(110)] CallMethodAndBlockWithTimeout(...): Domain=dbus, Code=org.freedesktop.DBus.Error.Failed, Message=gcd_server/notFound:Registration ticket not found Failed to receive a response: gcd_server/notFound:Registration ticket not found as opposed to just getting Device registered: Also detect when RegisterDevice() returns an empty string and set the error manually. This hack can be removed once RegisterDevice() has been fixed to always set an error when failing (e.g. returning an empty string). BUG=brillo:19 TEST=Manual test. Change-Id: Ia1b11c4039dd4474cd2a757634edc6fcd62c02b2 Reviewed-on: https://chromium-review.googlesource.com/249390 Reviewed-by: Alex Vakulenko <avakulenko@chromium.org> Commit-Queue: David Zeuthen <zeuthen@chromium.org> Tested-by: David Zeuthen <zeuthen@chromium.org>
diff --git a/buffet/device_registration_info.cc b/buffet/device_registration_info.cc index 413dc49..fb530b9 100644 --- a/buffet/device_registration_info.cc +++ b/buffet/device_registration_info.cc
@@ -388,8 +388,10 @@ error); if (!json_resp) return std::string(); - if (!response->IsSuccessful()) + if (!response->IsSuccessful()) { + ParseGCDError(json_resp.get(), error); return std::string(); + } url = GetServiceURL("registrationTickets/" + ticket_id_ + "/finalize?key=" + api_key_);
diff --git a/buffet/manager.cc b/buffet/manager.cc index 6605770..da90b00 100644 --- a/buffet/manager.cc +++ b/buffet/manager.cc
@@ -138,10 +138,18 @@ pair.first, pair.second.Get<std::string>()); } std::string device_id = device_info_->RegisterDevice(str_params, &error); - if (error) - response->ReplyWithError(error.get()); - else + if (!device_id.empty()) { response->Return(device_id); + return; + } + if (!error) { + // TODO(zeuthen): This can be changed to CHECK(error) once + // RegisterDevice() has been fixed to set |error| when failing. + chromeos::Error::AddTo(&error, FROM_HERE, kErrorDomainGCD, + "internal_error", + "device_id empty but error not set"); + } + response->ReplyWithError(error.get()); } void Manager::UpdateState(DBusMethodResponse<> response,