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 kUnknownCommitResult, ///< Retry commit on the same transaction; do not repeat its operations
57 };
58
59 TransactionException(Type type, std::string_view what);
60
61 Type GetType() const noexcept { return type_; }
62
63private:
64 Type type_;
65};
66
67/// Network (connectivity) error
69public:
70 using MongoException::MongoException;
71};
72
73/// No server available to satisfy request constraints
75public:
76 using MongoException::MongoException;
77};
78
79/// Incompatible server version
81public:
82 using MongoException::MongoException;
83};
84
85/// Authentication error
87public:
88 using MongoException::MongoException;
89};
90
91/// Generic query error
93public:
94 using MongoException::MongoException;
95};
96
97/// Query argument validation error
99public:
100 using QueryException::QueryException;
101};
102
103/// Server-side error
105public:
106 explicit ServerException(int code)
107 : code_(code)
108 {}
109
110 int Code() const { return code_; }
111
112private:
113 int code_;
114};
115
116/// Write concern error
118public:
119 using ServerException::ServerException;
120};
121
122/// Duplicate key error
124public:
125 using ServerException::ServerException;
126};
127
128} // namespace storages::mongo
129
130USERVER_NAMESPACE_END