storage: Add error handling when not found
Tested:
1. Miss ChassisId
~# curl -k -H "X-Auth-Token: $token" \
https://$bmc/redfish/v1/Chassis/G220AS/Drives/
```
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type Chassis named 'G220AS' was not found.",
"MessageArgs": [
"Chassis",
"G220AS"
],
"MessageId": "Base.1.16.0.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.16.0.ResourceNotFound",
"message": "The requested resource of type Chassis named 'G220AS' was not found."
}
}%
```
2. Miss ChassisId
~# curl -k -H "X-Auth-Token: $token" \
https://$bmc/redfish/v1/Chassis/G220AS/Drives/1
```
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type Chassis named 'G220AS' was not found.",
"MessageArgs": [
"Chassis",
"G220AS"
],
"MessageId": "Base.1.16.0.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.16.0.ResourceNotFound",
"message": "The requested resource of type Chassis named 'G220AS' was not found."
}
}%
```
3. Missing Drive name
~# curl -k -H "X-Auth-Token: $token" \
https://$bmc/redfish/v1/Chassis/G220A/Drives/sssss
```
{
"error": {
"@Message.ExtendedInfo": [
{
"@odata.type": "#Message.v1_1_1.Message",
"Message": "The requested resource of type Drives named 'sssss' was not found.",
"MessageArgs": [
"Drive",
"sssss"
],
"MessageId": "Base.1.16.0.ResourceNotFound",
"MessageSeverity": "Critical",
"Resolution": "Provide a valid resource identifier and resubmit the request."
}
],
"code": "Base.1.16.0.ResourceNotFound",
"message": "The requested resource of type Drives named 'sssss' was not found."
}
}%
```
Change-Id: I35c85f719f11aef5b8d89845e13163632ba99bf6
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 5b2d78e..a7243a0 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -953,8 +953,10 @@
matchAndFillDrive(asyncResp, chassisId, driveName,
resp);
});
- break;
+ return;
}
+ // Couldn't find an object with that name. return an error
+ messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
});
}