diff options
author | Adriana Kobylak <anoo@us.ibm.com> | 2021-02-11 18:33:10 +0300 |
---|---|---|
committer | Adriana Kobylak <anoo@us.ibm.com> | 2021-02-11 19:31:54 +0300 |
commit | ae34c8e888aba0108042acddbcf155a5c1a48992 (patch) | |
tree | 2d4e3720b31c0792ad493481946263090d8a6ddc | |
parent | 2b3da45876aac57a36d3093379a992d699e7e396 (diff) | |
download | bmcweb-ae34c8e888aba0108042acddbcf155a5c1a48992.tar.xz |
log_services: Improve error handling for DBus Log Entry
Improve the error handling of the DBus Log Entry class:
1. Return internal error only if message, id, or severity are
not initialized.
2. Handle Not Found error (404).
3. Escape the Entry ID used for the DBus call.
Tested:
A call to entries/foo returns not found:
$ curl -k -H "X-Auth-Token: $token" https://${bmc}/redfish/v1/Systems/system/LogServices/EventLog/Entries/foo
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type EventLogEntry named foo was not found.",
"MessageArgs": [
"EventLogEntry",
"foo"
],
"MessageId": "Base.1.8.1.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.8.1.ResourceNotFound",
"message": "The requested resource of type EventLogEntry named foo was not found."
}
Change-Id: Icac06b34c9d4bc570973da369eef42fd785b4bf7
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
-rw-r--r-- | redfish-core/lib/log_services.hpp | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index f22744b792..4975a37928 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -1412,20 +1412,12 @@ class DBusEventLogEntryCollection : public Node if (propertyMap.first == "Id") { id = std::get_if<uint32_t>(&propertyMap.second); - if (id == nullptr) - { - messages::internalError(asyncResp->res); - } } else if (propertyMap.first == "Timestamp") { const uint64_t* millisTimeStamp = std::get_if<uint64_t>(&propertyMap.second); - if (millisTimeStamp == nullptr) - { - messages::internalError(asyncResp->res); - } - else + if (millisTimeStamp != nullptr) { timestamp = crow::utility::getTimestamp( *millisTimeStamp); @@ -1435,11 +1427,7 @@ class DBusEventLogEntryCollection : public Node { const uint64_t* millisTimeStamp = std::get_if<uint64_t>(&propertyMap.second); - if (millisTimeStamp == nullptr) - { - messages::internalError(asyncResp->res); - } - else + if (millisTimeStamp != nullptr) { updateTimestamp = crow::utility::getTimestamp( @@ -1450,21 +1438,19 @@ class DBusEventLogEntryCollection : public Node { severity = std::get_if<std::string>( &propertyMap.second); - if (severity == nullptr) - { - messages::internalError(asyncResp->res); - } } else if (propertyMap.first == "Message") { message = std::get_if<std::string>( &propertyMap.second); - if (message == nullptr) - { - messages::internalError(asyncResp->res); - } } } + if (id == nullptr || message == nullptr || + severity == nullptr) + { + messages::internalError(asyncResp->res); + return; + } thisEntry = { {"@odata.type", "#LogEntry.v1_6_0.LogEntry"}, {"@odata.id", @@ -1522,13 +1508,20 @@ class DBusEventLogEntry : public Node messages::internalError(asyncResp->res); return; } - const std::string& entryID = params[0]; + std::string entryID = params[0]; + dbus::utility::escapePathForDbus(entryID); // DBus implementation of EventLog/Entries // Make call to Logging Service to find all log entry objects crow::connections::systemBus->async_method_call( [asyncResp, entryID](const boost::system::error_code ec, GetManagedPropertyType& resp) { + if (ec.value() == EBADR) + { + messages::resourceNotFound(asyncResp->res, "EventLogEntry", + entryID); + return; + } if (ec) { BMCWEB_LOG_ERROR @@ -1547,20 +1540,12 @@ class DBusEventLogEntry : public Node if (propertyMap.first == "Id") { id = std::get_if<uint32_t>(&propertyMap.second); - if (id == nullptr) - { - messages::internalError(asyncResp->res); - } } else if (propertyMap.first == "Timestamp") { const uint64_t* millisTimeStamp = std::get_if<uint64_t>(&propertyMap.second); - if (millisTimeStamp == nullptr) - { - messages::internalError(asyncResp->res); - } - else + if (millisTimeStamp != nullptr) { timestamp = crow::utility::getTimestamp(*millisTimeStamp); @@ -1570,11 +1555,7 @@ class DBusEventLogEntry : public Node { const uint64_t* millisTimeStamp = std::get_if<uint64_t>(&propertyMap.second); - if (millisTimeStamp == nullptr) - { - messages::internalError(asyncResp->res); - } - else + if (millisTimeStamp != nullptr) { updateTimestamp = crow::utility::getTimestamp(*millisTimeStamp); @@ -1584,22 +1565,15 @@ class DBusEventLogEntry : public Node { severity = std::get_if<std::string>(&propertyMap.second); - if (severity == nullptr) - { - messages::internalError(asyncResp->res); - } } else if (propertyMap.first == "Message") { message = std::get_if<std::string>(&propertyMap.second); - if (message == nullptr) - { - messages::internalError(asyncResp->res); - } } } if (id == nullptr || message == nullptr || severity == nullptr) { + messages::internalError(asyncResp->res); return; } asyncResp->res.jsonValue = { |