rippled
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
ripple::RPC::Status Struct Reference

Status represents the results of an operation that might fail. More...

Inheritance diagram for ripple::RPC::Status:
Inheritance graph
[legend]
Collaboration diagram for ripple::RPC::Status:
Collaboration graph
[legend]

Public Types

enum  Type { Type::none, Type::TER, Type::error_code_i }
 
using Code = int
 
using Strings = std::vector< std::string >
 

Public Member Functions

 Status ()=default
 
template<typename T , typename = std::enable_if_t<std::is_integral<T>::value>>
 Status (T code, Strings d={})
 
 Status (TER ter, Strings d={})
 
 Status (error_code_i e, Strings d={})
 
 Status (error_code_i e, std::string const &s)
 
std::string codeString () const
 
 operator bool () const
 Returns true if the Status is not OK. More...
 
bool operator! () const
 Returns true if the Status is OK. More...
 
TER toTER () const
 Returns the Status as a TER. More...
 
error_code_i toErrorCode () const
 Returns the Status as an error_code_i. More...
 
template<class Object >
void inject (Object &object) const
 Apply the Status to a JsonObject. More...
 
Strings const & messages () const
 
std::string message () const
 Return the first message, if any. More...
 
Type type () const
 
std::string toString () const
 
void fillJson (Json::Value &)
 Fill a Json::Value with an RPC 2.0 response. More...
 
what (T... args)
 

Static Public Attributes

static constexpr Code OK = 0
 

Private Attributes

Type type_ = Type::none
 
Code code_ = OK
 
Strings messages_
 

Detailed Description

Status represents the results of an operation that might fail.

It wraps the legacy codes TER and error_code_i, providing both a uniform interface and a way to attach additional information to existing status returns.

A Status can also be used to fill a Json::Value with a JSON-RPC 2.0 error response: see http://www.jsonrpc.org/specification#error_object

Definition at line 39 of file Status.h.

Member Typedef Documentation

◆ Code

Definition at line 43 of file Status.h.

◆ Strings

Definition at line 44 of file Status.h.

Member Enumeration Documentation

◆ Type

Enumerator
none 
TER 
error_code_i 

Definition at line 42 of file Status.h.

Constructor & Destructor Documentation

◆ Status() [1/5]

ripple::RPC::Status::Status ( )
default

◆ Status() [2/5]

template<typename T , typename = std::enable_if_t<std::is_integral<T>::value>>
ripple::RPC::Status::Status ( code,
Strings  d = {} 
)

Definition at line 54 of file Status.h.

◆ Status() [3/5]

ripple::RPC::Status::Status ( TER  ter,
Strings  d = {} 
)

Definition at line 59 of file Status.h.

◆ Status() [4/5]

ripple::RPC::Status::Status ( error_code_i  e,
Strings  d = {} 
)

Definition at line 64 of file Status.h.

◆ Status() [5/5]

ripple::RPC::Status::Status ( error_code_i  e,
std::string const &  s 
)

Definition at line 69 of file Status.h.

Member Function Documentation

◆ codeString()

std::string ripple::RPC::Status::codeString ( ) const

Definition at line 27 of file Status.cpp.

◆ operator bool()

ripple::RPC::Status::operator bool ( ) const

Returns true if the Status is not OK.

Definition at line 81 of file Status.h.

◆ operator!()

bool ripple::RPC::Status::operator! ( ) const

Returns true if the Status is OK.

Definition at line 88 of file Status.h.

◆ toTER()

TER ripple::RPC::Status::toTER ( ) const

Returns the Status as a TER.

This may only be called if type() == Type::TER.

Definition at line 96 of file Status.h.

◆ toErrorCode()

error_code_i ripple::RPC::Status::toErrorCode ( ) const

Returns the Status as an error_code_i.

This may only be called if type() == Type::error_code_i.

Definition at line 105 of file Status.h.

◆ inject()

template<class Object >
void ripple::RPC::Status::inject ( Object &  object) const

Apply the Status to a JsonObject.

Definition at line 115 of file Status.h.

◆ messages()

Strings const& ripple::RPC::Status::messages ( ) const

Definition at line 127 of file Status.h.

◆ message()

std::string ripple::RPC::Status::message ( ) const

Return the first message, if any.

Definition at line 78 of file Status.cpp.

◆ type()

Type ripple::RPC::Status::type ( ) const

Definition at line 137 of file Status.h.

◆ toString()

std::string ripple::RPC::Status::toString ( ) const

Definition at line 92 of file Status.cpp.

◆ fillJson()

void ripple::RPC::Status::fillJson ( Json::Value value)

Fill a Json::Value with an RPC 2.0 response.

If the Status is OK, fillJson has no effect. Not currently used.

Definition at line 59 of file Status.cpp.

Member Data Documentation

◆ OK

constexpr Code ripple::RPC::Status::OK = 0
staticconstexpr

Definition at line 46 of file Status.h.

◆ type_

Type ripple::RPC::Status::type_ = Type::none
private

Definition at line 152 of file Status.h.

◆ code_

Code ripple::RPC::Status::code_ = OK
private

Definition at line 153 of file Status.h.

◆ messages_

Strings ripple::RPC::Status::messages_
private

Definition at line 154 of file Status.h.