1 #include "utils/dbus_utils.hpp"
2 
3 #include "async_resp.hpp"
4 
5 #include <boost/system/error_code.hpp>
6 #include <nlohmann/json.hpp>
7 #include <sdbusplus/message.hpp>
8 
9 #include <memory>
10 #include <string>
11 #include <string_view>
12 
13 namespace redfish
14 {
15 namespace details
16 {
17 
18 void afterSetProperty(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
19                       const std::string& redfishPropertyName,
20                       const nlohmann::json& propertyValue,
21                       const boost::system::error_code& ec,
22                       const sdbusplus::message_t& msg)
23 {
24     if (ec)
25     {
26         if (ec.value() == boost::system::errc::permission_denied)
27         {
28             messages::insufficientPrivilege(asyncResp->res);
29         }
30         const sd_bus_error* dbusError = msg.get_error();
31         if (dbusError != nullptr)
32         {
33             std::string_view errorName(dbusError->name);
34 
35             if (errorName == "xyz.openbmc_project.Common.Error.InvalidArgument")
36             {
37                 BMCWEB_LOG_WARNING("DBUS response error: {}", ec);
38                 messages::propertyValueIncorrect(
39                     asyncResp->res, redfishPropertyName, propertyValue);
40                 return;
41             }
42             if (errorName ==
43                 "xyz.openbmc_project.State.Chassis.Error.BMCNotReady")
44             {
45                 BMCWEB_LOG_WARNING(
46                     "BMC not ready, operation not allowed right now");
47                 messages::serviceTemporarilyUnavailable(asyncResp->res, "10");
48                 return;
49             }
50             if (errorName == "xyz.openbmc_project.State.Host.Error.BMCNotReady")
51             {
52                 BMCWEB_LOG_WARNING(
53                     "BMC not ready, operation not allowed right now");
54                 messages::serviceTemporarilyUnavailable(asyncResp->res, "10");
55                 return;
56             }
57             if (errorName == "xyz.openbmc_project.Common.Error.NotAllowed")
58             {
59                 messages::propertyNotWritable(asyncResp->res,
60                                               redfishPropertyName);
61                 return;
62             }
63         }
64         BMCWEB_LOG_ERROR("D-Bus error setting Redfish Property {} ec={}",
65                          redfishPropertyName, ec);
66         messages::internalError(asyncResp->res);
67         return;
68     }
69     // Only set 204 if another erro hasn't already happened.
70     if (asyncResp->res.result() == boost::beast::http::status::ok)
71     {
72         asyncResp->res.result(boost::beast::http::status::no_content);
73     }
74 };
75 } // namespace details
76 } // namespace redfish
77