brbzull0 commented on code in PR #13022:
URL: https://github.com/apache/trafficserver/pull/13022#discussion_r2994872634
##########
include/mgmt/rpc/jsonrpc/json/YAMLCodec.h:
##########
@@ -193,8 +193,10 @@ class yamlcpp_json_encoder
json << YAML::Key << "data";
json << YAML::BeginSeq;
for (auto const &err : errata) {
+ int severity = err.severity(ERRATA_DIAG);
json << YAML::BeginMap;
- json << YAML::Key << "code" << YAML::Value << errata.code().value();
+ // using "code" as the key here because this is decoded into a
`JSONRPCError`
+ json << YAML::Key << "code" << YAML::Value << severity;
Review Comment:
I think if use the severity here in the code field we are changing the
meaning from "error code" to "severity level" which is not the original
intention.
I think we should use severity as part of the error definition instead:
```c++
// the only new stuff would be the severity.
struct JSONRPCError {
int32_t code;
std::string message;
struct DataEntry {
int32_t code;
int32_t severity{-1}; // -1 = not present (assume ERROR)
std::string message;
};
std::vector<DataEntry> data;
};
```
This can be set by the handlers as you already did in the test, something
like this:
```
resp.errata().assign(std::error_code{errors::Codes::SERVER})
.note(ERRATA_WARN, "Server already draining.");
// json:
{
"jsonrpc": "2.0",
"error": {
"code": 9,
"message": "Error during execution",
"data": [
{
"code": 2,
"severity": 4,
"message": "Server already draining."
}
]
},
"id": "..."
}
```
then we can add the severity if present:
```cpp
for (auto const &err : errata) {
json << YAML::BeginMap;
json << YAML::Key << "code" << YAML::Value << errata.code().value();
if (err.has_severity()) {
json << YAML::Key << "severity" << YAML::Value
<< static_cast<int>(err.severity());
}
json << YAML::Key << "message" << YAML::Value
<< std::string{err.text().data(), err.text().size()};
json << YAML::EndMap;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]