AWS SDK for C++

AWS SDK for C++ Version 1.11.847

Loading...
Searching...
No Matches
AWSError.h
1
6#pragma once
7
8#include <aws/core/Core_EXPORTS.h>
9#include <aws/core/utils/memory/stl/AWSString.h>
10#include <aws/core/http/HttpResponse.h>
11#include <aws/core/utils/xml/XmlSerializer.h>
12#include <aws/core/utils/json/JsonSerializer.h>
13#include <aws/core/utils/StringUtils.h>
14
15namespace Aws
16{
17 namespace Client
18 {
19 enum class CoreErrors;
20 class XmlErrorMarshaller;
21 class JsonErrorMarshaller;
22
24 {
25 NOT_SET,
26 XML,
27 JSON
28 };
29
30 enum class RetryableType
31 {
35 };
36
40 template<typename ERROR_TYPE>
42 {
43 // Allow ErrorMarshaller to set error payload.
44 friend class XmlErrorMarshaller;
45 friend class JsonErrorMarshaller;
47 template<typename T> friend class AWSError;
48 public:
54 {}
55
59 AWSError(ERROR_TYPE errorType,
60 Aws::String exceptionName,
61 Aws::String message,
62 bool isRetryable) :
63 AWSError(errorType,
65 exceptionName,
66 message)
67 {}
68
72 AWSError(ERROR_TYPE errorType,
73 bool isRetryable) :
74 AWSError(errorType,
76 {}
77
81 AWSError(ERROR_TYPE errorType,
82 RetryableType retryableType,
83 Aws::String exceptionName = "",
84 Aws::String message = "") :
85 m_errorType(errorType),
86 m_exceptionName(std::move(exceptionName)),
87 m_message(std::move(message)),
88 m_retryableType(retryableType)
89 {}
90
91 AWSError(AWSError&&) = default;
92 AWSError(const AWSError&) = default;
93
94 template<typename OTHER_ERROR_TYPE>
96 m_errorType(static_cast<ERROR_TYPE>(rhs.m_errorType)),
97 m_exceptionName(std::move(rhs.m_exceptionName)),
98 m_message(std::move(rhs.m_message)),
100 m_requestId(std::move(rhs.m_requestId)),
101 m_responseHeaders(std::move(rhs.m_responseHeaders)),
104 m_xmlPayload(std::move(rhs.m_xmlPayload)),
105 m_jsonPayload(std::move(rhs.m_jsonPayload)),
107 {}
108
109 template<typename OTHER_ERROR_TYPE>
111 m_errorType(static_cast<ERROR_TYPE>(rhs.m_errorType)),
113 m_message(rhs.m_message),
122 {}
123
128
133
137 inline const ERROR_TYPE GetErrorType() const { return m_errorType; }
141 inline const Aws::String& GetExceptionName() const { return m_exceptionName; }
145 inline void SetExceptionName(const Aws::String& exceptionName) { m_exceptionName = exceptionName; }
149#ifdef _WIN32
150 #pragma push_macro("GetMessage")
151#undef GetMessage
152 inline const Aws::String& GetMessage() const { return m_message; }
153 inline const Aws::String& GetMessageW() const { return GetMessage(); }
154 inline const Aws::String& GetMessageA() const { return GetMessage(); }
155
156#pragma pop_macro("GetMessage")
157#else
158 inline const Aws::String& GetMessage() const { return m_message; }
159#endif //#ifdef _WIN32
163 inline void SetMessage(const Aws::String& message) { m_message = message; }
173 inline void SetRemoteHostIpAddress(const Aws::String& remoteHostIpAddress) { m_remoteHostIpAddress = remoteHostIpAddress; }
179 inline const Aws::String& GetRequestId() const { return m_requestId; }
183 inline void SetRequestId(const Aws::String& requestId) { m_requestId = requestId; }
199 inline bool ResponseHeaderExists(const Aws::String& headerName) const { return m_responseHeaders.find(Aws::Utils::StringUtils::ToLower(headerName.c_str())) != m_responseHeaders.end(); }
207 inline void SetResponseCode(Aws::Http::HttpResponseCode responseCode) { m_responseCode = responseCode; }
215 inline void SetRetryableType(const RetryableType retryableType) { m_retryableType = retryableType; }
216
217 protected:
219 inline void SetXmlPayload(const Aws::Utils::Xml::XmlDocument& xmlPayload)
220 {
222 m_xmlPayload = xmlPayload;
223 }
225 {
227 m_xmlPayload = std::move(xmlPayload);
228 }
230 {
232 return m_xmlPayload;
233 }
234 inline void SetJsonPayload(const Aws::Utils::Json::JsonValue& jsonPayload)
235 {
237 m_jsonPayload = jsonPayload;
238 }
240 {
242 m_jsonPayload = std::move(jsonPayload);
243 }
245 {
247 return m_jsonPayload;
248 }
249
250 ERROR_TYPE m_errorType;
257
262 };
263
264 template<typename T>
266 {
267 s << "HTTP response code: " << static_cast<int>(e.GetResponseCode()) << "\n"
268 << "Resolved remote host IP address: " << e.GetRemoteHostIpAddress() << "\n"
269 << "Request ID: " << e.GetRequestId() << "\n"
270 << "Exception name: " << e.GetExceptionName() << "\n"
271 << "Error message: " << e.GetMessage() << "\n"
272 << e.GetResponseHeaders().size() << " response headers:";
273
274 for (auto&& header : e.GetResponseHeaders())
275 {
276 s << "\n" << header.first << " : " << header.second;
277 }
278 return s;
279 }
280
281 } // namespace Client
282} // namespace Aws
void SetRequestId(const Aws::String &requestId)
Definition AWSError.h:183
void SetXmlPayload(const Aws::Utils::Xml::XmlDocument &xmlPayload)
Definition AWSError.h:219
bool ResponseHeaderExists(const Aws::String &headerName) const
Definition AWSError.h:199
Aws::String m_remoteHostIpAddress
Definition AWSError.h:253
ERROR_TYPE m_errorType
Definition AWSError.h:250
ErrorPayloadType m_errorPayloadType
Definition AWSError.h:258
AWSError(const AWSError &)=default
Aws::String m_exceptionName
Definition AWSError.h:251
const Aws::Http::HeaderValueCollection & GetResponseHeaders() const
Definition AWSError.h:191
AWSError(AWSError< OTHER_ERROR_TYPE > &&rhs)
Definition AWSError.h:95
const Aws::String & GetRequestId() const
Definition AWSError.h:179
void SetRemoteHostIpAddress(const Aws::String &remoteHostIpAddress)
Definition AWSError.h:173
Aws::Utils::Xml::XmlDocument m_xmlPayload
Definition AWSError.h:259
Aws::Http::HttpResponseCode m_responseCode
Definition AWSError.h:256
const Aws::String & GetRemoteHostIpAddress() const
Definition AWSError.h:169
AWSError & operator=(AWSError< ERROR_TYPE > &&)=default
const Aws::String & GetMessage() const
Definition AWSError.h:158
AWSError(ERROR_TYPE errorType, bool isRetryable)
Definition AWSError.h:72
RetryableType m_retryableType
Definition AWSError.h:261
bool ShouldRetry() const
Definition AWSError.h:187
void SetResponseHeaders(const Aws::Http::HeaderValueCollection &headers)
Definition AWSError.h:195
ErrorPayloadType GetErrorPayloadType()
Definition AWSError.h:218
const Aws::Utils::Xml::XmlDocument & GetXmlPayload() const
Definition AWSError.h:229
AWSError & operator=(const AWSError< ERROR_TYPE > &)=default
const Aws::String & GetExceptionName() const
Definition AWSError.h:141
void SetResponseCode(Aws::Http::HttpResponseCode responseCode)
Definition AWSError.h:207
Aws::Http::HeaderValueCollection m_responseHeaders
Definition AWSError.h:255
void SetRetryableType(const RetryableType retryableType)
Definition AWSError.h:215
Aws::String m_requestId
Definition AWSError.h:254
AWSError(ERROR_TYPE errorType, RetryableType retryableType, Aws::String exceptionName="", Aws::String message="")
Definition AWSError.h:81
const Aws::Utils::Json::JsonValue & GetJsonPayload() const
Definition AWSError.h:244
bool ShouldThrottle() const
Definition AWSError.h:211
Aws::Utils::Json::JsonValue m_jsonPayload
Definition AWSError.h:260
void SetExceptionName(const Aws::String &exceptionName)
Definition AWSError.h:145
void SetJsonPayload(Aws::Utils::Json::JsonValue &&jsonPayload)
Definition AWSError.h:239
AWSError(ERROR_TYPE errorType, Aws::String exceptionName, Aws::String message, bool isRetryable)
Definition AWSError.h:59
AWSError(const AWSError< OTHER_ERROR_TYPE > &rhs)
Definition AWSError.h:110
void SetXmlPayload(Aws::Utils::Xml::XmlDocument &&xmlPayload)
Definition AWSError.h:224
Aws::Http::HttpResponseCode GetResponseCode() const
Definition AWSError.h:203
const ERROR_TYPE GetErrorType() const
Definition AWSError.h:137
void SetJsonPayload(const Aws::Utils::Json::JsonValue &jsonPayload)
Definition AWSError.h:234
AWSError(AWSError &&)=default
Aws::String m_message
Definition AWSError.h:252
static Aws::String ToLower(const char *source)
Aws::OStream & operator<<(Aws::OStream &s, const AWSError< T > &e)
Definition AWSError.h:265
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition HttpTypes.h:56
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition AWSString.h:97
std::basic_ostream< char, std::char_traits< char > > OStream