mirror of
https://github.com/XRPLF/clio.git
synced 2026-04-29 15:37:53 +00:00
@@ -214,28 +214,31 @@ private:
|
||||
// if the result is forwarded - just use it as is
|
||||
// if forwarded request has error, for http, error should be in "result"; for ws, error should
|
||||
// be at top
|
||||
if (isForwarded && (json.contains("result") || connection->upgraded)) {
|
||||
if (isForwarded && (json.contains(JS(result)) || connection->upgraded)) {
|
||||
for (auto const& [k, v] : json)
|
||||
response.insert_or_assign(k, v);
|
||||
} else {
|
||||
response["result"] = json;
|
||||
response[JS(result)] = json;
|
||||
}
|
||||
|
||||
// for ws there is an additional field "status" in the response,
|
||||
// otherwise the "status" is in the "result" field
|
||||
if (connection->upgraded) {
|
||||
auto const id = request.contains("id") ? request.at("id") : nullptr;
|
||||
auto const appendFieldIfExist = [&](auto const& field) {
|
||||
if (request.contains(field) and not request.at(field).is_null())
|
||||
response[field] = request.at(field);
|
||||
};
|
||||
|
||||
if (not id.is_null())
|
||||
response["id"] = id;
|
||||
appendFieldIfExist(JS(id));
|
||||
appendFieldIfExist(JS(api_version));
|
||||
|
||||
if (!response.contains("error"))
|
||||
response["status"] = "success";
|
||||
if (!response.contains(JS(error)))
|
||||
response[JS(status)] = JS(success);
|
||||
|
||||
response["type"] = "response";
|
||||
response[JS(type)] = JS(response);
|
||||
} else {
|
||||
if (response.contains("result") && !response["result"].as_object().contains("error"))
|
||||
response["result"].as_object()["status"] = "success";
|
||||
if (response.contains(JS(result)) && !response[JS(result)].as_object().contains(JS(error)))
|
||||
response[JS(result)].as_object()[JS(status)] = JS(success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,18 +150,23 @@ public:
|
||||
auto e = rpc::makeError(error);
|
||||
|
||||
if (request_) {
|
||||
auto const& req = request_.value();
|
||||
auto const id = req.contains("id") ? req.at("id") : nullptr;
|
||||
if (not id.is_null())
|
||||
e["id"] = id;
|
||||
auto const appendFieldIfExist = [&](auto const& field) {
|
||||
if (request_->contains(field) and not request_->at(field).is_null())
|
||||
e[field] = request_->at(field);
|
||||
};
|
||||
|
||||
e["request"] = req;
|
||||
appendFieldIfExist(JS(id));
|
||||
|
||||
if (connection_->upgraded)
|
||||
appendFieldIfExist(JS(api_version));
|
||||
|
||||
e[JS(request)] = request_.value();
|
||||
}
|
||||
|
||||
if (connection_->upgraded) {
|
||||
return e;
|
||||
}
|
||||
return {{"result", e}};
|
||||
return {{JS(result), e}};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user