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