mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
fix: Print out error details of web context (#2351)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
//==============================================================================
|
||||
|
||||
#include "rpc/Errors.hpp"
|
||||
#include "util/NameGenerator.hpp"
|
||||
|
||||
#include <boost/json/fwd.hpp>
|
||||
#include <boost/json/object.hpp>
|
||||
@@ -139,7 +140,7 @@ TEST(RPCErrorsTest, InvalidClioErrorToJSON)
|
||||
}
|
||||
|
||||
struct WarningCodeTestBundle {
|
||||
std::string name;
|
||||
std::string testName;
|
||||
WarningCode code;
|
||||
std::string message;
|
||||
};
|
||||
@@ -166,7 +167,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
"https://xrpl.org/docs/references/http-websocket-apis/ and update your request."
|
||||
}
|
||||
),
|
||||
[](testing::TestParamInfo<WarningCodeTestBundle> const& info) { return info.param.name; }
|
||||
tests::util::kNAME_GENERATOR
|
||||
);
|
||||
|
||||
TEST_P(WarningCodeTest, WarningToJSON)
|
||||
@@ -189,3 +190,69 @@ TEST(RPCErrorsTest, InvalidWarningToJSON)
|
||||
};
|
||||
EXPECT_ANY_THROW((void)notSanitizedMakeWarning());
|
||||
}
|
||||
|
||||
struct StatusStreamTestBundle {
|
||||
std::string testName;
|
||||
rpc::Status status;
|
||||
std::string expectedOutput;
|
||||
};
|
||||
|
||||
struct RPCErrorsStatusStreamTest : public ::testing::TestWithParam<StatusStreamTestBundle> {
|
||||
protected:
|
||||
std::ostringstream oss;
|
||||
};
|
||||
|
||||
TEST_P(RPCErrorsStatusStreamTest, StatusStreamOperator)
|
||||
{
|
||||
auto const param = GetParam();
|
||||
oss << param.status;
|
||||
EXPECT_EQ(oss.str(), param.expectedOutput);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
RPCErrorsTest,
|
||||
RPCErrorsStatusStreamTest,
|
||||
testing::Values(
|
||||
StatusStreamTestBundle{
|
||||
.testName = "EmptyStatus",
|
||||
.status = Status{},
|
||||
.expectedOutput = "Code: 0, Message: An unknown error code."
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithRippledError",
|
||||
.status = Status{RippledError::rpcSUCCESS},
|
||||
.expectedOutput = "Code: 0, Message: An unknown error code."
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithClioError",
|
||||
.status = Status{ClioError::RpcParamsUnparsable},
|
||||
.expectedOutput = "Code: 6004, Message: Params must be an array holding exactly one object."
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithCodeAndExtraInfo",
|
||||
.status = Status{ClioError::EtlConnectionError, boost::json::object{}},
|
||||
.expectedOutput = "Code: 7000, Message: Couldn't connect to rippled., Extra Info: {}"
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithMessage",
|
||||
.status = Status{"test message."},
|
||||
.expectedOutput = "Code: -1, Message: test message."
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithRippledErrorAndMessage",
|
||||
.status = Status{RippledError::rpcSUCCESS, "test message."},
|
||||
.expectedOutput = "Code: 0, Message: test message."
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithClioErrorAndMessage",
|
||||
.status = Status{ClioError::RpcParamsUnparsable, "Missing params array."},
|
||||
.expectedOutput = "Code: 6004, Message: Missing params array."
|
||||
},
|
||||
StatusStreamTestBundle{
|
||||
.testName = "StatusWithCodeErrorMessage",
|
||||
.status = Status{ClioError::EtlInvalidResponse, "invalidResponse", "Rippled returned an invalid response."},
|
||||
.expectedOutput = "Code: 7003, Error: invalidResponse, Message: Rippled returned an invalid response."
|
||||
}
|
||||
),
|
||||
tests::util::kNAME_GENERATOR
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user