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>
requires (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
 If the Status is OK, the result is an empty string.
 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 26 of file Status.h.

Member Typedef Documentation

◆ Code

Definition at line 30 of file Status.h.

◆ Strings

Definition at line 31 of file Status.h.

Member Enumeration Documentation

◆ Type

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

Definition at line 29 of file Status.h.

Constructor & Destructor Documentation

◆ Status() [1/5]

xrpl::rpc::Status::Status ( )
default

◆ Status() [2/5]

template<typename T>
requires (std::is_integral_v<T>)
xrpl::rpc::Status::Status ( T code,
Strings d = {} )

Definition at line 39 of file Status.h.

◆ Status() [3/5]

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

Definition at line 45 of file Status.h.

◆ Status() [4/5]

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

Definition at line 50 of file Status.h.

◆ Status() [5/5]

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

Definition at line 55 of file Status.h.

Member Function Documentation

◆ codeString()

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

If the Status is OK, the result is an empty string.

Returns
a representation of the integer status Code as a string.

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 70 of file Status.h.

◆ operator!()

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

Returns true if the Status is OK.

Definition at line 79 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 89 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 100 of file Status.h.

◆ inject()

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

Apply the Status to a JsonObject.

Definition at line 111 of file Status.h.

◆ messages()

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

Definition at line 127 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 139 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 33 of file Status.h.

◆ type_

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

Definition at line 156 of file Status.h.

◆ code_

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

Definition at line 157 of file Status.h.

◆ messages_

Strings xrpl::rpc::Status::messages_
private

Definition at line 158 of file Status.h.