#include <response.hpp>
Definition at line 16 of file response.hpp.
◆ Response() [1/3]
jsonrpc::endpoint::Response::Response |
( |
| ) |
|
|
default |
◆ Response() [2/3]
jsonrpc::endpoint::Response::Response |
( |
const Response & | | ) |
|
|
default |
◆ Response() [3/3]
jsonrpc::endpoint::Response::Response |
( |
Response && | other | ) |
|
|
default |
◆ ~Response()
jsonrpc::endpoint::Response::~Response |
( |
| ) |
|
|
default |
◆ CreateError() [1/3]
auto jsonrpc::endpoint::Response::CreateError |
( |
const nlohmann::json & | error, |
|
|
const std::optional< RequestId > & | id ) -> Response |
|
static |
◆ CreateError() [2/3]
auto jsonrpc::endpoint::Response::CreateError |
( |
const RpcError & | error, |
|
|
const std::optional< RequestId > & | id = std::nullopt ) -> Response |
|
static |
Definition at line 43 of file response.cpp.
44 {
45 nlohmann::json error_json = error.to_json();
47}
static auto CreateError(RpcErrorCode code, const std::optional< RequestId > &id=std::nullopt) -> Response
◆ CreateError() [3/3]
auto jsonrpc::endpoint::Response::CreateError |
( |
RpcErrorCode | code, |
|
|
const std::optional< RequestId > & | id = std::nullopt ) -> Response |
|
static |
Definition at line 28 of file response.cpp.
29 {
31
32 nlohmann::json error = {
33 {"code", static_cast<int>(err.Code())}, {"message", err.Message()}};
34 nlohmann::json response = {{
"jsonrpc",
kJsonRpcVersion}, {
"error", error}};
35 if (id) {
36 std::visit([&response](const auto& v) { response["id"] = v; }, *id);
37 } else {
38 response["id"] = nullptr;
39 }
40 return Response{std::move(response)};
41}
static auto FromCode(RpcErrorCode code, std::string message="") -> RpcError
References jsonrpc::error::RpcError::Code(), jsonrpc::error::RpcError::FromCode(), jsonrpc::endpoint::kJsonRpcVersion, and jsonrpc::error::RpcError::Message().
Referenced by jsonrpc::endpoint::Dispatcher::DispatchRequest().
◆ CreateSuccess()
auto jsonrpc::endpoint::Response::CreateSuccess |
( |
const nlohmann::json & | result, |
|
|
const std::optional< RequestId > & | id ) -> Response |
|
static |
◆ FromJson()
auto jsonrpc::endpoint::Response::FromJson |
( |
const nlohmann::json & | json | ) |
-> std::expected<Response, error::RpcError> |
|
static |
Definition at line 9 of file response.cpp.
10 {
12 if (auto result = r.ValidateResponse(); !result) {
13 return std::unexpected(result.error());
14 }
15 return r;
16}
◆ GetError()
auto jsonrpc::endpoint::Response::GetError |
( |
| ) |
const -> const nlohmann::json& |
|
nodiscard |
Definition at line 70 of file response.cpp.
70 {
72 throw std::runtime_error("Response is not an error response");
73 }
74 return response_["error"];
75}
auto IsSuccess() const -> bool
References IsSuccess().
◆ GetId()
auto jsonrpc::endpoint::Response::GetId |
( |
| ) |
const -> std::optional<RequestId> |
|
nodiscard |
Definition at line 77 of file response.cpp.
77 {
78 if (!response_.contains("id") || response_["id"].is_null()) {
79 return std::nullopt;
80 }
81
82 const auto& id = response_["id"];
83 if (id.is_string()) {
84 return id.get<std::string>();
85 }
86 return id.get<int64_t>();
87}
◆ GetResult()
auto jsonrpc::endpoint::Response::GetResult |
( |
| ) |
const -> const nlohmann::json& |
|
nodiscard |
Definition at line 63 of file response.cpp.
63 {
65 throw std::runtime_error("Response is not a success response");
66 }
67 return response_["result"];
68}
References IsSuccess().
◆ IsSuccess()
auto jsonrpc::endpoint::Response::IsSuccess |
( |
| ) |
const -> bool |
|
nodiscard |
◆ operator=() [1/2]
auto jsonrpc::endpoint::Response::operator= |
( |
const Response & | | ) |
-> Response &=default |
|
default |
◆ operator=() [2/2]
auto jsonrpc::endpoint::Response::operator= |
( |
Response && | other | ) |
-> Response &=default |
|
defaultnoexcept |
◆ ToJson()
auto jsonrpc::endpoint::Response::ToJson |
( |
| ) |
const -> nlohmann::json |
|
nodiscard |
The documentation for this class was generated from the following files: