rippled
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
xrpl::RPC::Status Struct Reference

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

#include <Status.h>

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

Public Types

enum class  Type { none , TER , 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.
 
bool operator! () const
 Returns true if the Status is OK.
 
TER toTER () const
 Returns the Status as a TER.
 
error_code_i toErrorCode () const
 Returns the Status as an error_code_i.
 
void inject (Json::Value &object) const
 Apply the Status to a JsonObject.
 
Strings const & messages () const
 
std::string message () const
 Return the first message, if any.
 
Type type () const
 
std::string toString () const
 
void fillJson (Json::Value &)
 Fill a Json::Value with an RPC 2.0 response.
 
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 19 of file Status.h.

Member Typedef Documentation

◆ Code

Definition at line 23 of file Status.h.

◆ Strings

Definition at line 24 of file Status.h.

Member Enumeration Documentation

◆ Type

enum class xrpl::RPC::Status::Type
strong
Enumerator
none 
TER 
error_code_i 

Definition at line 22 of file Status.h.

Constructor & Destructor Documentation

◆ Status() [1/5]

xrpl::RPC::Status::Status ( )
default

◆ Status() [2/5]

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

Definition at line 32 of file Status.h.

◆ Status() [3/5]

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

Definition at line 36 of file Status.h.

◆ Status() [4/5]

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

Definition at line 40 of file Status.h.

◆ Status() [5/5]

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

Definition at line 44 of file Status.h.

Member Function Documentation

◆ codeString()

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

Definition at line 9 of file Status.cpp.

◆ operator bool()

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

Returns true if the Status is not OK.

Definition at line 55 of file Status.h.

◆ operator!()

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

Returns true if the Status is OK.

Definition at line 62 of file Status.h.

◆ toTER()

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

Returns the Status as a TER.

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

Definition at line 70 of file Status.h.

◆ toErrorCode()

error_code_i xrpl::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 79 of file Status.h.

◆ inject()

void xrpl::RPC::Status::inject ( Json::Value object) const

Apply the Status to a JsonObject.

Definition at line 88 of file Status.h.

◆ messages()

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

Definition at line 100 of file Status.h.

◆ message()

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

Return the first message, if any.

Definition at line 61 of file Status.cpp.

◆ type()

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

Definition at line 110 of file Status.h.

◆ toString()

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

Definition at line 75 of file Status.cpp.

◆ fillJson()

void xrpl::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 42 of file Status.cpp.

Member Data Documentation

◆ OK

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

Definition at line 26 of file Status.h.

◆ type_

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

Definition at line 125 of file Status.h.

◆ code_

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

Definition at line 126 of file Status.h.

◆ messages_

Strings xrpl::RPC::Status::messages_
private

Definition at line 127 of file Status.h.