userver: userver/storages/mongo/exception.hpp Source File
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/mongo/exception.hpp
4/// @brief MongoDB-specific exceptions
5
6#include <userver/utils/traceful_exception.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace storages::mongo {
11
12/// Generic mongo-related exception
13class MongoException : public utils::TracefulException {
14public:
15 MongoException();
16
17 explicit MongoException(std::string_view what);
18};
19
20/// Config validation error
22 using MongoException::MongoException;
23};
24
25/// The current task has been cancelled, e.g. by deadline propagation
27public:
28 struct ByDeadlinePropagation final {};
29
30 using MongoException::MongoException;
31
32 explicit CancelledException(ByDeadlinePropagation);
33
34 bool IsByDeadlinePropagation() const;
35
36private:
37 bool by_deadline_propagation_{false};
38};
39
40/// Nonexistent pool requested from the set
42 using MongoException::MongoException;
43};
44
45/// Pool refused to satisfy connection request due to high load
47 using MongoException::MongoException;
48};
49
50/// Transaction-related exception
52public:
53 enum class Type {
54 kTransientError, ///< Transient error that may be retried
55 kPermanentError, ///< Permanent error, cannot retry
56 };
57
58 TransactionException(Type type, std::string_view what);
59
60 Type GetType() const noexcept { return type_; }
61
62private:
63 Type type_;
64};
65
66/// Network (connectivity) error
68public:
69 using MongoException::MongoException;
70};
71
72/// No server available to satisfy request constraints
74public:
75 using MongoException::MongoException;
76};
77
78/// Incompatible server version
80public:
81 using MongoException::MongoException;
82};
83
84/// Authentication error
86public:
87 using MongoException::MongoException;
88};
89
90/// Generic query error
92public:
93 using MongoException::MongoException;
94};
95
96/// Query argument validation error
98public:
99 using QueryException::QueryException;
100};
101
102/// Server-side error
104public:
105 explicit ServerException(int code)
106 : code_(code)
107 {}
108
109 int Code() const { return code_; }
110
111private:
112 int code_;
113};
114
115/// Write concern error
117public:
118 using ServerException::ServerException;
119};
120
121/// Duplicate key error
123public:
124 using ServerException::ServerException;
125};
126
127} // namespace storages::mongo
128
129USERVER_NAMESPACE_END