Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Error.hpp
1#pragma once
2
3#include <cassandra.h>
4
5#include <cstdint>
6#include <ostream>
7#include <string>
8#include <utility>
9
10namespace data::cassandra {
11
15class CassandraError {
16 std::string message_;
17 uint32_t code_{};
18
19public:
20 // default constructible required by Expected
21 CassandraError() = default;
22
29 CassandraError(std::string message, uint32_t code) : message_{std::move(message)}, code_{code}
30 {
31 }
32
34 template <typename T>
35 friend std::string
36 operator+(T const& lhs, CassandraError const& rhs)
37 requires std::is_convertible_v<T, std::string>
38 {
39 return lhs + rhs.message();
40 }
41
42 template <typename T>
43 friend bool
44 operator==(T const& lhs, CassandraError const& rhs)
45 requires std::is_convertible_v<T, std::string>
46 {
47 return lhs == rhs.message();
48 }
49
50 template <std::integral T>
51 friend bool
52 operator==(T const& lhs, CassandraError const& rhs)
53 {
54 return lhs == rhs.code();
55 }
56
57 friend std::ostream&
58 operator<<(std::ostream& os, CassandraError const& err)
59 {
60 os << err.message();
61 return os;
62 }
64
68 std::string
69 message() const
70 {
71 return message_;
72 }
73
77 uint32_t
78 code() const
79 {
80 return code_;
81 }
82
86 bool
87 isTimeout() const
88 {
89 return code_ == CASS_ERROR_LIB_NO_HOSTS_AVAILABLE or
90 code_ == CASS_ERROR_LIB_REQUEST_TIMED_OUT or code_ == CASS_ERROR_SERVER_UNAVAILABLE or
91 code_ == CASS_ERROR_SERVER_OVERLOADED or code_ == CASS_ERROR_SERVER_READ_TIMEOUT;
92 }
93
97 bool
99 {
100 return code_ == CASS_ERROR_SERVER_INVALID_QUERY;
101 }
102};
103
104} // namespace data::cassandra
A simple container for both error message and error code.
Definition Error.hpp:15
CassandraError(std::string message, uint32_t code)
Construct a new CassandraError object.
Definition Error.hpp:29
bool isTimeout() const
Definition Error.hpp:87
bool isInvalidQuery() const
Definition Error.hpp:98
uint32_t code() const
Definition Error.hpp:78
std::string message() const
Definition Error.hpp:69
This namespace implements a wrapper for the Cassandra C++ driver.
Definition CassandraBackendFamily.hpp:47
std::ostream & operator<<(std::ostream &stream, Status const &status)
Definition Errors.cpp:26