summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNan Zhou <nanzhoumails@gmail.com>2022-05-27 20:23:04 +0300
committerNan Zhou <nanzhoumails@gmail.com>2022-05-27 21:01:52 +0300
commit1a1d5d6d06458f23e0c86aceda1c807c7553217a (patch)
tree307d164dc027656482a3dbb19e62715718d3386f
parent30f11eb44c906c59401a3532e1d4094318e00e02 (diff)
downloadbmcweb-1a1d5d6d06458f23e0c86aceda1c807c7553217a.tar.xz
memory: set @odata attributes only if the object is found
The existing code returns a JSON payload with @odata attributes even if it is a 404 not found. This commit corrects that by moving @odata after the object is found. Tested: 1. before ``` { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm5", "@odata.type": "#Memory.v1_11_0.Memory", "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Memory named 'dimm5' was not found.", "MessageArgs": [ "Memory", "dimm5" ], "MessageId": "Base.1.11.0.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.11.0.ResourceNotFound", "message": "The requested resource of type Memory named 'dimm5' was not found." } } ``` after ``` { "error": { "@Message.ExtendedInfo": [ { "@odata.type": "#Message.v1_1_1.Message", "Message": "The requested resource of type Memory named 'dimm5' was not found.", "MessageArgs": [ "Memory", "dimm5" ], "MessageId": "Base.1.11.0.ResourceNotFound", "MessageSeverity": "Critical", "Resolution": "Provide a valid resource identifier and resubmit the request." } ], "code": "Base.1.11.0.ResourceNotFound", "message": "The requested resource of type Memory named 'dimm5' was not found." } } ``` 2. Service Validator on MemoryResource passes. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: Id0f912015b0ecf25cacb22e919ebe88708187677
-rw-r--r--redfish-core/lib/memory.hpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index 4e9b4b7e86..68be9a762d 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -845,7 +845,12 @@ inline void getDimmData(std::shared_ptr<bmcweb::AsyncResp> aResp,
if (!found)
{
messages::resourceNotFound(aResp->res, "Memory", dimmId);
+ return;
}
+ // Set @odata only if object is found
+ aResp->res.jsonValue["@odata.type"] = "#Memory.v1_11_0.Memory";
+ aResp->res.jsonValue["@odata.id"] =
+ "/redfish/v1/Systems/system/Memory/" + dimmId;
return;
},
"xyz.openbmc_project.ObjectMapper",
@@ -898,11 +903,6 @@ inline void requestRoutesMemory(App& app)
{
return;
}
- asyncResp->res.jsonValue["@odata.type"] =
- "#Memory.v1_11_0.Memory";
- asyncResp->res.jsonValue["@odata.id"] =
- "/redfish/v1/Systems/system/Memory/" + dimmId;
-
getDimmData(asyncResp, dimmId);
});
}