userver: userver/clients/http/error.hpp Source File
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/clients/http/error.hpp
4/// @brief HTTP client exception types
5
6#include <exception>
7#include <string>
8#include <string_view>
9#include <system_error>
10
11#include <userver/clients/http/error_kind.hpp>
12#include <userver/clients/http/local_stats.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace clients::http {
17
18/// Exception with string
19class BaseException : public std::exception {
20public:
21 BaseException(std::string message, const LocalStats& stats, ErrorKind error_kind)
22 : message_(std::move(message)),
23 stats_(stats),
24 error_kind_(error_kind)
25 {}
26 ~BaseException() override = default;
27
28 const char* what() const noexcept override { return message_.c_str(); }
29
30 ErrorKind GetErrorKind() const { return error_kind_; }
31
32 const LocalStats& GetStats() const { return stats_; }
33
34private:
35 std::string message_;
36 LocalStats stats_;
37 ErrorKind error_kind_;
38};
39
40/// Exception with string and error_code
42public:
43 BaseCodeException(std::error_code ec, std::string_view message, std::string_view url, const LocalStats& stats);
44 ~BaseCodeException() override = default;
45
46 const std::error_code& error_code() const noexcept { return ec_; }
47
48private:
49 std::error_code ec_;
50};
51
53public:
54 TimeoutException(std::string_view message, const LocalStats& stats);
55 ~TimeoutException() override = default;
56};
57
59public:
60 using BaseException::BaseException;
61 ~CancelException() override = default;
62};
63
65public:
66 using BaseCodeException::BaseCodeException;
67 ~SSLException() override = default;
68};
69
71public:
72 using BaseCodeException::BaseCodeException;
73 ~TechnicalError() override = default;
74};
75
77public:
78 using BaseCodeException::BaseCodeException;
79 ~BadArgumentException() override = default;
80};
81
83public:
84 using BaseCodeException::BaseCodeException;
85 ~TooManyRedirectsException() override = default;
86};
87
89public:
90 using BaseCodeException::BaseCodeException;
91 ~NetworkProblemException() override = default;
92};
93
95public:
96 using BaseCodeException::BaseCodeException;
97 ~DNSProblemException() override = default;
98};
99
101public:
102 using BaseCodeException::BaseCodeException;
103 ~AuthFailedException() override = default;
104};
105
106/// Base class for HttpClientException and HttpServerException
108public:
109 HttpException(int code, const LocalStats& stats, std::string_view message, ErrorKind error_kind);
110 ~HttpException() override = default;
111
112 int code() const { return code_; }
113
114private:
115 int code_;
116};
117
119public:
120 HttpClientException(int code, const LocalStats& stats);
121 HttpClientException(int code, const LocalStats& stats, std::string_view message);
122 ~HttpClientException() override = default;
123};
124
126public:
127 HttpServerException(int code, const LocalStats& stats);
128 HttpServerException(int code, const LocalStats& stats, std::string_view message);
129 ~HttpServerException() override = default;
130};
131
132/// map error_code to exceptions
133std::exception_ptr PrepareException(std::error_code ec, std::string_view url, const LocalStats& stats);
134
135} // namespace clients::http
136
137USERVER_NAMESPACE_END