5
6
7
8
14 return id.is_string() || id.is_number() || id.is_null() || id.is_discarded();
19 auto id = request.contains(
"id") ? request[
"id"] : nlohmann::json(
nullptr);
20 return is_valid_request_id(id) ? id : nlohmann::json(
nullptr);
25 return response.is_discarded() ? std::string{} : response.dump();
30 return response.is_object() && response.contains(
"error") && response[
"error"].is_object();
35 return response.at(
"error").value(
"code", 0);
40 return response.at(
"error").value(
"message",
"");
48 {
"error", e.to_json()},
JSON RPC Exception class.
WWA_JSONRPC_EXPORT std::string serialize_repsonse(const nlohmann::json &response)
Serializes the JSON RPC response to a string.
WWA_JSONRPC_EXPORT std::string get_error_message(const nlohmann::json &response)
Gets the error message from an error response.
WWA_JSONRPC_EXPORT bool is_error_response(const nlohmann::json &response)
Checks whether response is an error response.
WWA_JSONRPC_EXPORT bool is_valid_request_id(const nlohmann::json &id)
Checks if the provided JSON value is a valid JSON RPC request ID.
WWA_JSONRPC_EXPORT nlohmann::json generate_error_response(const exception &e, const nlohmann::json &id=nlohmann::json::value_t::null)
Generates an error response.
WWA_JSONRPC_EXPORT nlohmann::json get_request_id(const nlohmann::json &request)
Get the request id object.
WWA_JSONRPC_EXPORT int get_error_code(const nlohmann::json &response)
Gets the error code from an error response.