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