xrpld
Loading...
Searching...
No Matches
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:
Collaboration diagram for xrpl::RPC::Status:

Public Types

enum class  Type { None , TER , ErrorCodeI }
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_v<T>>>
 Status (T code, Strings d={})
 Status (TER ter, Strings d={})
 Status (ErrorCodeI e, Strings d={})
 Status (ErrorCodeI 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.
ErrorCodeI 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 kOK = 0

Private Attributes

Type type_ = Type::None
Code code_ = kOK
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 18 of file Status.h.

Member Typedef Documentation

◆ Code

Definition at line 22 of file Status.h.

◆ Strings

Definition at line 23 of file Status.h.

Member Enumeration Documentation

◆ Type

enum class xrpl::RPC::Status::Type
strong
Enumerator
None 
TER 
ErrorCodeI 

Definition at line 21 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_v<T>>>
xrpl::RPC::Status::Status ( T code,
Strings d = {} )

Definition at line 31 of file Status.h.

◆ Status() [3/5]

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

Definition at line 35 of file Status.h.

◆ Status() [4/5]

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

Definition at line 40 of file Status.h.

◆ Status() [5/5]

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

Definition at line 45 of file Status.h.

Member Function Documentation

◆ codeString()

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

Definition at line 15 of file Status.cpp.

◆ operator bool()

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

Returns true if the Status is not OK.

Definition at line 56 of file Status.h.

◆ operator!()

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

Returns true if the Status is OK.

Definition at line 63 of file Status.h.

◆ toTER()

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

Returns the Status as a TER.

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

Definition at line 71 of file Status.h.

◆ toErrorCode()

ErrorCodeI xrpl::RPC::Status::toErrorCode ( ) const
nodiscard

Returns the Status as an error_code_i.

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

Definition at line 80 of file Status.h.

◆ inject()

void xrpl::RPC::Status::inject ( json::Value & object) const

Apply the Status to a JsonObject.

Definition at line 89 of file Status.h.

◆ messages()

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

Definition at line 105 of file Status.h.

◆ message()

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

Return the first message, if any.

Definition at line 67 of file Status.cpp.

◆ type()

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

Definition at line 115 of file Status.h.

◆ toString()

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

Definition at line 81 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 48 of file Status.cpp.

Member Data Documentation

◆ kOK

Code xrpl::RPC::Status::kOK = 0
staticconstexpr

Definition at line 25 of file Status.h.

◆ type_

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

Definition at line 130 of file Status.h.

◆ code_

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

Definition at line 131 of file Status.h.

◆ messages_

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

Definition at line 132 of file Status.h.