xrpld
Loading...
Searching...
No Matches
Status.cpp
1#include <xrpld/rpc/Status.h>
2
3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/json/json_value.h>
5#include <xrpl/protocol/ErrorCodes.h>
6#include <xrpl/protocol/TER.h>
7#include <xrpl/protocol/jss.h>
8
9#include <sstream>
10#include <string>
11
12namespace xrpl::RPC {
13
14std::string
16{
17 if (!*this)
18 return "";
19
20 if (type_ == Type::None)
21 return std::to_string(code_);
22
24 {
25 std::string s1, s2;
26
27 [[maybe_unused]] auto const success = transResultInfo(toTER(), s1, s2);
28 XRPL_ASSERT(success, "xrpl::RPC::codeString : valid TER result");
29
30 return s1 + ": " + s2;
31 }
32
34 {
35 auto info = getErrorInfo(toErrorCode());
37 sStr << info.token.cStr() << ": " << info.message.cStr();
38 return sStr.str();
39 }
40
41 // LCOV_EXCL_START
42 UNREACHABLE("xrpl::RPC::codeString : invalid type");
43 return "";
44 // LCOV_EXCL_STOP
45}
46
47void
49{
50 if (!*this)
51 return;
52
53 auto& error = value[jss::error];
54 error[jss::code] = code_;
55 error[jss::message] = codeString();
56
57 // Are there any more messages?
58 if (!messages_.empty())
59 {
60 auto& messages = error[jss::data];
61 for (auto& i : messages_)
62 messages.append(i);
63 }
64}
65
68{
69 std::string result;
70 for (auto& m : messages_)
71 {
72 if (!result.empty())
73 result += '/';
74 result += m;
75 }
76
77 return result;
78}
79
82{
83 if (*this)
84 return codeString() + ":" + message();
85 return "";
86}
87
88} // namespace xrpl::RPC
Represents a JSON value.
Definition json_value.h:130
T empty(T... args)
API version numbers used in later API versions.
Definition ApiVersion.h:35
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:232
T str(T... args)
Strings const & messages() const
Definition Status.h:105
std::string message() const
Return the first message, if any.
Definition Status.cpp:67
std::string codeString() const
Definition Status.cpp:15
TER toTER() const
Returns the Status as a TER.
Definition Status.h:71
void fillJson(json::Value &)
Fill a json::Value with an RPC 2.0 response.
Definition Status.cpp:48
Strings messages_
Definition Status.h:132
ErrorCodeI toErrorCode() const
Returns the Status as an error_code_i.
Definition Status.h:80
std::string toString() const
Definition Status.cpp:81
T to_string(T... args)