rippled
Loading...
Searching...
No Matches
Status.cpp
1#include <xrpld/rpc/Status.h>
2
3#include <sstream>
4
5namespace ripple {
6namespace RPC {
7
10{
11 if (!*this)
12 return "";
13
14 if (type_ == Type::none)
15 return std::to_string(code_);
16
18 {
19 std::string s1, s2;
20
21 [[maybe_unused]] auto const success = transResultInfo(toTER(), s1, s2);
22 XRPL_ASSERT(success, "ripple::RPC::codeString : valid TER result");
23
24 return s1 + ": " + s2;
25 }
26
28 {
29 auto info = get_error_info(toErrorCode());
31 sStr << info.token.c_str() << ": " << info.message.c_str();
32 return sStr.str();
33 }
34
35 // LCOV_EXCL_START
36 UNREACHABLE("ripple::RPC::codeString : invalid type");
37 return "";
38 // LCOV_EXCL_STOP
39}
40
41void
43{
44 if (!*this)
45 return;
46
47 auto& error = value[jss::error];
48 error[jss::code] = code_;
49 error[jss::message] = codeString();
50
51 // Are there any more messages?
52 if (!messages_.empty())
53 {
54 auto& messages = error[jss::data];
55 for (auto& i : messages_)
56 messages.append(i);
57 }
58}
59
62{
63 std::string result;
64 for (auto& m : messages_)
65 {
66 if (!result.empty())
67 result += '/';
68 result += m;
69 }
70
71 return result;
72}
73
76{
77 if (*this)
78 return codeString() + ":" + message();
79 return "";
80}
81
82} // namespace RPC
83} // namespace ripple
Represents a JSON value.
Definition json_value.h:130
T empty(T... args)
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool transResultInfo(TER code, std::string &token, std::string &text)
Definition TER.cpp:230
T str(T... args)
Strings const & messages() const
Definition Status.h:111
error_code_i toErrorCode() const
Returns the Status as an error_code_i.
Definition Status.h:87
std::string toString() const
Definition Status.cpp:75
std::string message() const
Return the first message, if any.
Definition Status.cpp:61
Strings messages_
Definition Status.h:138
TER toTER() const
Returns the Status as a TER.
Definition Status.h:77
std::string codeString() const
Definition Status.cpp:9
void fillJson(Json::Value &)
Fill a Json::Value with an RPC 2.0 response.
Definition Status.cpp:42
T to_string(T... args)