userver: userver/storages/mongo/mongo_error.hpp Source File
Loading...
Searching...
No Matches
mongo_error.hpp
1#pragma once
2
3#include <string>
4
5#include <bson/bson.h>
6
7USERVER_NAMESPACE_BEGIN
8
9namespace storages::mongo {
10
11/// MongoDB error
12class MongoError {
13 public:
14 /// Error kinds
15 enum class Kind {
16 kNoError, ///< Error was not reported correctly
17 kNetwork, ///< @copybrief NetworkException
18 kClusterUnavailable, ///< @copybrief ClusterUnavailableException
19 kIncompatibleServer, ///< @copybrief IncompatibleServerException
20 kAuthentication, ///< @copybrief AuthenticationException
21 kQuery, ///< @copybrief QueryException
22 kInvalidQueryArgument, ///< @copybrief InvalidQueryArgumentException
23 kServer, ///< @copybrief ServerException
24 kWriteConcern, ///< @copybrief WriteConcernException
25 kDuplicateKey, ///< @copybrief DuplicateKeyException
26 kOther ///< Unclassified error
27 };
28
29 /// @cond
30 /// Creates a not-an-error
31 MongoError();
32 /// @endcond
33
34 /// Checks whether an error is set up
35 explicit operator bool() const;
36
37 /// Checks whether this is a server error
38 bool IsServerError() const;
39 Kind GetKind() const;
40
41 uint32_t Code() const;
42 const char* Message() const;
43
44 /// @cond
45 /// Error domain, for internal use
46 uint32_t Domain() const;
47
48 /// Returns native type, internal use only
49 bson_error_t* GetNative();
50 /// @endcond
51
52 /// Unconditionally throws specialized MongoException
53 [[noreturn]] void Throw(std::string prefix) const;
54
55 private:
56 bson_error_t value_;
57};
58
59} // namespace storages::mongo
60
61USERVER_NAMESPACE_END