JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
jsonrpc::error::RpcError Class Reference

#include <error.hpp>

Collaboration diagram for jsonrpc::error::RpcError:

Public Member Functions

 RpcError (RpcErrorCode code, std::string message)
 
auto to_json () const -> nlohmann::json
 
auto Code () const -> RpcErrorCode
 
auto Message () const -> std::string
 
auto operator== (const RpcError &other) const -> bool
 
auto operator!= (const RpcError &other) const -> bool
 

Static Public Member Functions

static auto FromCode (RpcErrorCode code, std::string message="") -> RpcError
 
static auto UnexpectedFromCode (RpcErrorCode code, std::string message="") -> std::unexpected< RpcError >
 

Detailed Description

Definition at line 64 of file error.hpp.

Constructor & Destructor Documentation

◆ RpcError()

jsonrpc::error::RpcError::RpcError ( RpcErrorCode code,
std::string message )
inline

Definition at line 66 of file error.hpp.

67 : code_(code), message_(std::move(message)) {
68 }

Member Function Documentation

◆ Code()

auto jsonrpc::error::RpcError::Code ( ) const -> RpcErrorCode
inlinenodiscard

Definition at line 77 of file error.hpp.

77 {
78 return code_;
79 }

Referenced by jsonrpc::endpoint::Response::CreateError(), operator==(), and to_json().

Here is the caller graph for this function:

◆ FromCode()

static auto jsonrpc::error::RpcError::FromCode ( RpcErrorCode code,
std::string message = "" ) -> RpcError
inlinestatic

Definition at line 93 of file error.hpp.

94 {
95 if (message.empty()) {
96 message = std::string(detail::DefaultMessageFor(code));
97 }
98 return {code, std::move(message)};
99 }
auto DefaultMessageFor(RpcErrorCode code) -> std::string_view
Definition error.hpp:33

References jsonrpc::error::detail::DefaultMessageFor().

Referenced by jsonrpc::endpoint::Response::CreateError(), and UnexpectedFromCode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Message()

auto jsonrpc::error::RpcError::Message ( ) const -> std::string
inlinenodiscard

Definition at line 81 of file error.hpp.

81 {
82 return message_;
83 }

Referenced by jsonrpc::endpoint::Response::CreateError(), operator==(), and to_json().

Here is the caller graph for this function:

◆ operator!=()

auto jsonrpc::error::RpcError::operator!= ( const RpcError & other) const -> bool
inline

Definition at line 89 of file error.hpp.

89 {
90 return !(*this == other);
91 }

◆ operator==()

auto jsonrpc::error::RpcError::operator== ( const RpcError & other) const -> bool
inline

Definition at line 85 of file error.hpp.

85 {
86 return Code() == other.Code() && Message() == other.Message();
87 }
auto Code() const -> RpcErrorCode
Definition error.hpp:77
auto Message() const -> std::string
Definition error.hpp:81

References Code(), and Message().

Here is the call graph for this function:

◆ to_json()

auto jsonrpc::error::RpcError::to_json ( ) const -> nlohmann::json
inlinenodiscard

Definition at line 70 of file error.hpp.

70 {
71 nlohmann::json json;
72 json["code"] = static_cast<int>(Code());
73 json["message"] = Message();
74 return json;
75 }

References Code(), and Message().

Here is the call graph for this function:

◆ UnexpectedFromCode()

static auto jsonrpc::error::RpcError::UnexpectedFromCode ( RpcErrorCode code,
std::string message = "" ) -> std::unexpected<RpcError>
inlinestatic

The documentation for this class was generated from the following file: