AWS SDK for C++  1.9.74
AWS SDK for C++
AWSError.h
Go to the documentation of this file.
1 
6 #pragma once
7 
14 
15 // TODO: temporary fix for naming conflicts on Windows.
16 #ifdef _WIN32
17 #ifdef GetMessage
18 #undef GetMessage
19 #endif
20 #endif
21 
22 namespace Aws
23 {
24  namespace Client
25  {
26  enum class CoreErrors;
27  class XmlErrorMarshaller;
28  class JsonErrorMarshaller;
29 
30  enum class ErrorPayloadType
31  {
32  NOT_SET,
33  XML,
34  JSON
35  };
36 
40  template<typename ERROR_TYPE>
41  class AWSError
42  {
43  // Allow ErrorMarshaller to set error payload.
44  friend class XmlErrorMarshaller;
45  friend class JsonErrorMarshaller;
46  template<typename T> friend class AWSError;
47  public:
51  AWSError() : m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE), m_isRetryable(false) {}
55  AWSError(ERROR_TYPE errorType, Aws::String exceptionName, const Aws::String message, bool isRetryable) :
56  m_errorType(errorType), m_exceptionName(exceptionName), m_message(message),
57  m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE), m_isRetryable(isRetryable),
62  AWSError(ERROR_TYPE errorType, bool isRetryable) :
63  m_errorType(errorType), m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
64  m_isRetryable(isRetryable), m_errorPayloadType(ErrorPayloadType::NOT_SET) {}
65 
66  AWSError(AWSError&&) = default;
67  AWSError(const AWSError&) = default;
68 
69  template<typename OTHER_ERROR_TYPE>
71  m_errorType(static_cast<ERROR_TYPE>(rhs.m_errorType)), m_exceptionName(std::move(rhs.m_exceptionName)),
72  m_message(std::move(rhs.m_message)), m_remoteHostIpAddress(std::move(rhs.m_remoteHostIpAddress)),
73  m_requestId(std::move(rhs.m_requestId)), m_responseHeaders(std::move(rhs.m_responseHeaders)),
75  m_xmlPayload(std::move(rhs.m_xmlPayload)), m_jsonPayload(std::move(rhs.m_jsonPayload))
76  {}
77 
78  template<typename OTHER_ERROR_TYPE>
80  m_errorType(static_cast<ERROR_TYPE>(rhs.m_errorType)), m_exceptionName(rhs.m_exceptionName),
85  {}
86 
91 
96 
100  inline const ERROR_TYPE GetErrorType() const { return m_errorType; }
104  inline const Aws::String& GetExceptionName() const { return m_exceptionName; }
108  inline void SetExceptionName(const Aws::String& exceptionName) { m_exceptionName = exceptionName; }
112  inline const Aws::String& GetMessage() const { return m_message; }
116  inline void SetMessage(const Aws::String& message) { m_message = message; }
122  inline const Aws::String& GetRemoteHostIpAddress() const { return m_remoteHostIpAddress; }
126  inline void SetRemoteHostIpAddress(const Aws::String& remoteHostIpAddress) { m_remoteHostIpAddress = remoteHostIpAddress; }
132  inline const Aws::String& GetRequestId() const { return m_requestId; }
136  inline void SetRequestId(const Aws::String& requestId) { m_requestId = requestId; }
140  inline bool ShouldRetry() const { return m_isRetryable; }
148  inline void SetResponseHeaders(const Aws::Http::HeaderValueCollection& headers) { m_responseHeaders = headers; }
152  inline bool ResponseHeaderExists(const Aws::String& headerName) const { return m_responseHeaders.find(Aws::Utils::StringUtils::ToLower(headerName.c_str())) != m_responseHeaders.end(); }
160  inline void SetResponseCode(Aws::Http::HttpResponseCode responseCode) { m_responseCode = responseCode; }
161 
162  protected:
164  inline void SetXmlPayload(const Aws::Utils::Xml::XmlDocument& xmlPayload)
165  {
166  m_errorPayloadType = ErrorPayloadType::XML;
167  m_xmlPayload = xmlPayload;
168  }
169  inline void SetXmlPayload(Aws::Utils::Xml::XmlDocument&& xmlPayload)
170  {
171  m_errorPayloadType = ErrorPayloadType::XML;
172  m_xmlPayload = std::move(xmlPayload);
173  }
175  {
177  return m_xmlPayload;
178  }
179  inline void SetJsonPayload(const Aws::Utils::Json::JsonValue& jsonPayload)
180  {
182  m_jsonPayload = jsonPayload;
183  }
184  inline void SetJsonPayload(Aws::Utils::Json::JsonValue&& jsonPayload)
185  {
187  m_jsonPayload = std::move(jsonPayload);
188  }
190  {
191  assert(m_errorPayloadType != ErrorPayloadType::XML);
192  return m_jsonPayload;
193  }
194 
195  ERROR_TYPE m_errorType;
203 
207  };
208 
209  template<typename T>
211  {
212  s << "HTTP response code: " << static_cast<int>(e.GetResponseCode()) << "\n"
213  << "Resolved remote host IP address: " << e.GetRemoteHostIpAddress() << "\n"
214  << "Request ID: " << e.GetRequestId() << "\n"
215  << "Exception name: " << e.GetExceptionName() << "\n"
216  << "Error message: " << e.GetMessage() << "\n"
217  << e.GetResponseHeaders().size() << " response headers:";
218 
219  for (auto&& header : e.GetResponseHeaders())
220  {
221  s << "\n" << header.first << " : " << header.second;
222  }
223  return s;
224  }
225 
226  } // namespace Client
227 } // namespace Aws
Aws::Client::AWSError::m_errorPayloadType
ErrorPayloadType m_errorPayloadType
Definition: AWSError.h:204
Aws::Client::AWSError::ShouldRetry
bool ShouldRetry() const
Definition: AWSError.h:140
Aws::DirectoryService::Model::LDAPSType::NOT_SET
@ NOT_SET
Aws::Client::AWSError::m_isRetryable
bool m_isRetryable
Definition: AWSError.h:202
Aws::Client::AWSError::SetRemoteHostIpAddress
void SetRemoteHostIpAddress(const Aws::String &remoteHostIpAddress)
Definition: AWSError.h:126
Aws::Client::AWSError::GetErrorPayloadType
ErrorPayloadType GetErrorPayloadType()
Definition: AWSError.h:163
Aws::Client::CoreErrors
CoreErrors
Definition: CoreErrors.h:21
Aws::Http::HeaderValueCollection
Aws::Map< Aws::String, Aws::String > HeaderValueCollection
Definition: HttpTypes.h:53
Aws::Client::AWSError::m_errorType
ERROR_TYPE m_errorType
Definition: AWSError.h:195
Aws::Client::AWSError::SetResponseHeaders
void SetResponseHeaders(const Aws::Http::HeaderValueCollection &headers)
Definition: AWSError.h:148
Aws::Client::AWSError::SetXmlPayload
void SetXmlPayload(const Aws::Utils::Xml::XmlDocument &xmlPayload)
Definition: AWSError.h:164
Aws::Client::AWSError::GetErrorType
const ERROR_TYPE GetErrorType() const
Definition: AWSError.h:100
Aws::Client::AWSError::SetMessage
void SetMessage(const Aws::String &message)
Definition: AWSError.h:116
Aws::Client::AWSError::GetXmlPayload
const Aws::Utils::Xml::XmlDocument & GetXmlPayload() const
Definition: AWSError.h:174
Aws::Client::AWSError::operator=
AWSError & operator=(const AWSError< ERROR_TYPE > &)=default
Aws::Client::AWSError::m_responseCode
Aws::Http::HttpResponseCode m_responseCode
Definition: AWSError.h:201
Aws::Http::HttpResponseCode
HttpResponseCode
Definition: HttpResponse.h:30
Aws::Client::AWSError::AWSError
AWSError(ERROR_TYPE errorType, bool isRetryable)
Definition: AWSError.h:62
Aws::Client::AWSError::ResponseHeaderExists
bool ResponseHeaderExists(const Aws::String &headerName) const
Definition: AWSError.h:152
Aws::Client::JsonErrorMarshaller
Definition: AWSErrorMarshaller.h:69
Aws::Client::XmlErrorMarshaller
Definition: AWSErrorMarshaller.h:83
Aws::Client::AWSError::AWSError
AWSError(const AWSError &)=default
Aws::Client::AWSError::SetXmlPayload
void SetXmlPayload(Aws::Utils::Xml::XmlDocument &&xmlPayload)
Definition: AWSError.h:169
Aws::Client::AWSError::GetResponseCode
Aws::Http::HttpResponseCode GetResponseCode() const
Definition: AWSError.h:156
Aws::Client::AWSError::AWSError
AWSError(AWSError &&)=default
Aws::Client::AWSError::m_requestId
Aws::String m_requestId
Definition: AWSError.h:199
Aws::Client::AWSError::m_message
Aws::String m_message
Definition: AWSError.h:197
Aws::OStream
std::basic_ostream< char, std::char_traits< char > > OStream
Definition: AWSStreamFwd.h:21
Aws::Client::AWSError::AWSError
AWSError(ERROR_TYPE errorType, Aws::String exceptionName, const Aws::String message, bool isRetryable)
Definition: AWSError.h:55
Aws::Client::AWSError::SetExceptionName
void SetExceptionName(const Aws::String &exceptionName)
Definition: AWSError.h:108
Aws::Client::AWSError::GetResponseHeaders
const Aws::Http::HeaderValueCollection & GetResponseHeaders() const
Definition: AWSError.h:144
Aws::Client::AWSError::operator=
AWSError & operator=(AWSError< ERROR_TYPE > &&other)=default
Aws::Client::AWSError::GetJsonPayload
const Aws::Utils::Json::JsonValue & GetJsonPayload() const
Definition: AWSError.h:189
Aws::Client::AWSError::GetExceptionName
const Aws::String & GetExceptionName() const
Definition: AWSError.h:104
Aws::Client::AWSError::SetRequestId
void SetRequestId(const Aws::String &requestId)
Definition: AWSError.h:136
Aws::Client::AWSError::GetRequestId
const Aws::String & GetRequestId() const
Definition: AWSError.h:132
XmlSerializer.h
Aws::Client::AWSError::AWSError
AWSError(AWSError< OTHER_ERROR_TYPE > &&rhs)
Definition: AWSError.h:70
AWSString.h
Aws::Utils::Json::JsonValue
Definition: JsonSerializer.h:30
Aws::Client::AWSError
Definition: AWSError.h:42
HttpResponse.h
Aws::Utils::Xml::XmlDocument
Definition: XmlSerializer.h:156
StringUtils.h
Aws::Client::AWSError::m_remoteHostIpAddress
Aws::String m_remoteHostIpAddress
Definition: AWSError.h:198
Aws::Client::ErrorPayloadType::NOT_SET
@ NOT_SET
Aws::Client::AWSError::m_responseHeaders
Aws::Http::HeaderValueCollection m_responseHeaders
Definition: AWSError.h:200
Core_EXPORTS.h
Aws
Definition: AccessManagementClient.h:15
Aws::Client::AWSError::SetJsonPayload
void SetJsonPayload(Aws::Utils::Json::JsonValue &&jsonPayload)
Definition: AWSError.h:184
Aws::Client::AWSError::GetRemoteHostIpAddress
const Aws::String & GetRemoteHostIpAddress() const
Definition: AWSError.h:122
Aws::Client::AWSError::m_jsonPayload
Aws::Utils::Json::JsonValue m_jsonPayload
Definition: AWSError.h:206
Aws::String
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String
Definition: AWSString.h:97
Aws::Client::operator<<
Aws::OStream & operator<<(Aws::OStream &s, const AWSError< T > &e)
Definition: AWSError.h:210
Aws::Client::AWSError::m_xmlPayload
Aws::Utils::Xml::XmlDocument m_xmlPayload
Definition: AWSError.h:205
Aws::Client::AWSError::m_exceptionName
Aws::String m_exceptionName
Definition: AWSError.h:196
Aws::Client::ErrorPayloadType
ErrorPayloadType
Definition: AWSError.h:31
Aws::Client::AWSError::AWSError
AWSError()
Definition: AWSError.h:51
Aws::Client::AWSError::SetJsonPayload
void SetJsonPayload(const Aws::Utils::Json::JsonValue &jsonPayload)
Definition: AWSError.h:179
Aws::Client::AWSError::GetMessage
const Aws::String & GetMessage() const
Definition: AWSError.h:112
Aws::Client::AWSError::SetResponseCode
void SetResponseCode(Aws::Http::HttpResponseCode responseCode)
Definition: AWSError.h:160
JsonSerializer.h
Aws::Client::AWSError::AWSError
AWSError(const AWSError< OTHER_ERROR_TYPE > &rhs)
Definition: AWSError.h:79
Aws::Utils::StringUtils::ToLower
static Aws::String ToLower(const char *source)