Fix getService fail on single host platform
Add exception handling in the getService() function to so that the
isMultiHost() function returns correct value for single and multi-host
platform.
Tested: check on single host platform
1. Press power button and check if it works properly
2. Press reset button and check if it work properly
Signed-off-by: Thang Q. Nguyen <thang@os.amperecomputing.com>
Change-Id: I5c7019fb27b6ccb795ada9c63e591ce8561ff70c
diff --git a/src/button_handler.cpp b/src/button_handler.cpp
index 054f642..4a477fa 100644
--- a/src/button_handler.cpp
+++ b/src/button_handler.cpp
@@ -129,12 +129,17 @@
auto method = bus.new_method_call(mapperService, mapperObjPath, mapperIface,
"GetObject");
method.append(path, std::vector{interface});
- auto result = bus.call(method);
-
- std::map<std::string, std::vector<std::string>> objectData;
- result.read(objectData);
-
- return objectData.begin()->first;
+ try
+ {
+ auto result = bus.call(method);
+ std::map<std::string, std::vector<std::string>> objectData;
+ result.read(objectData);
+ return objectData.begin()->first;
+ }
+ catch (const sdbusplus::exception::exception& e)
+ {
+ return std::string();
+ }
}
size_t Handler::getHostSelectorValue()
{