AWS SDK for C++  1.8.184
AWS SDK for C++
AWSError.h
Go to the documentation of this file.
1 
6 #pragma once
7 
14 
15 namespace Aws
16 {
17  namespace Client
18  {
19  enum class CoreErrors;
20  class XmlErrorMarshaller;
21  class JsonErrorMarshaller;
22 
23  enum class ErrorPayloadType
24  {
25  NOT_SET,
26  XML,
27  JSON
28  };
29 
33  template<typename ERROR_TYPE>
34  class AWSError
35  {
36  // Allow ErrorMarshaller to set error payload.
37  friend class XmlErrorMarshaller;
38  friend class JsonErrorMarshaller;
39  template<typename T> friend class AWSError;
40  public:
44  AWSError() : m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE), m_isRetryable(false) {}
48  AWSError(ERROR_TYPE errorType, Aws::String exceptionName, const Aws::String message, bool isRetryable) :
49  m_errorType(errorType), m_exceptionName(exceptionName), m_message(message),
50  m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE), m_isRetryable(isRetryable),
55  AWSError(ERROR_TYPE errorType, bool isRetryable) :
56  m_errorType(errorType), m_responseCode(Aws::Http::HttpResponseCode::REQUEST_NOT_MADE),
57  m_isRetryable(isRetryable), m_errorPayloadType(ErrorPayloadType::NOT_SET) {}
58 
59  AWSError(AWSError&&) = default;
60  AWSError(const AWSError&) = default;
61 
62  template<typename OTHER_ERROR_TYPE>
64  m_errorType(static_cast<ERROR_TYPE>(rhs.m_errorType)), m_exceptionName(std::move(rhs.m_exceptionName)),
65  m_message(std::move(rhs.m_message)), m_remoteHostIpAddress(std::move(rhs.m_remoteHostIpAddress)),
66  m_requestId(std::move(rhs.m_requestId)), m_responseHeaders(std::move(rhs.m_responseHeaders)),
68  m_xmlPayload(std::move(rhs.m_xmlPayload)), m_jsonPayload(std::move(rhs.m_jsonPayload))
69  {}
70 
71  template<typename OTHER_ERROR_TYPE>
73  m_errorType(static_cast<ERROR_TYPE>(rhs.m_errorType)), m_exceptionName(rhs.m_exceptionName),
78  {}
79 
84 
89 
93  inline const ERROR_TYPE GetErrorType() const { return m_errorType; }
97  inline const Aws::String& GetExceptionName() const { return m_exceptionName; }
101  inline void SetExceptionName(const Aws::String& exceptionName) { m_exceptionName = exceptionName; }
105  inline const Aws::String& GetMessage() const { return m_message; }
109  inline void SetMessage(const Aws::String& message) { m_message = message; }
115  inline const Aws::String& GetRemoteHostIpAddress() const { return m_remoteHostIpAddress; }
119  inline void SetRemoteHostIpAddress(const Aws::String& remoteHostIpAddress) { m_remoteHostIpAddress = remoteHostIpAddress; }
125  inline const Aws::String& GetRequestId() const { return m_requestId; }
129  inline void SetRequestId(const Aws::String& requestId) { m_requestId = requestId; }
133  inline bool ShouldRetry() const { return m_isRetryable; }
141  inline void SetResponseHeaders(const Aws::Http::HeaderValueCollection& headers) { m_responseHeaders = headers; }
145  inline bool ResponseHeaderExists(const Aws::String& headerName) const { return m_responseHeaders.find(Aws::Utils::StringUtils::ToLower(headerName.c_str())) != m_responseHeaders.end(); }
153  inline void SetResponseCode(Aws::Http::HttpResponseCode responseCode) { m_responseCode = responseCode; }
154 
155  protected:
157  inline void SetXmlPayload(const Aws::Utils::Xml::XmlDocument& xmlPayload)
158  {
159  m_errorPayloadType = ErrorPayloadType::XML;
160  m_xmlPayload = xmlPayload;
161  }
162  inline void SetXmlPayload(Aws::Utils::Xml::XmlDocument&& xmlPayload)
163  {
164  m_errorPayloadType = ErrorPayloadType::XML;
165  m_xmlPayload = std::move(xmlPayload);
166  }
168  {
170  return m_xmlPayload;
171  }
172  inline void SetJsonPayload(const Aws::Utils::Json::JsonValue& jsonPayload)
173  {
175  m_jsonPayload = jsonPayload;
176  }
177  inline void SetJsonPayload(Aws::Utils::Json::JsonValue&& jsonPayload)
178  {
180  m_jsonPayload = std::move(jsonPayload);
181  }
183  {
184  assert(m_errorPayloadType != ErrorPayloadType::XML);
185  return m_jsonPayload;
186  }
187 
188  ERROR_TYPE m_errorType;
196 
200  };
201 
202  template<typename T>
204  {
205  s << "HTTP response code: " << static_cast<int>(e.GetResponseCode()) << "\n"
206  << "Resolved remote host IP address: " << e.GetRemoteHostIpAddress() << "\n"
207  << "Request ID: " << e.GetRequestId() << "\n"
208  << "Exception name: " << e.GetExceptionName() << "\n"
209  << "Error message: " << e.GetMessage() << "\n"
210  << e.GetResponseHeaders().size() << " response headers:";
211 
212  for (auto&& header : e.GetResponseHeaders())
213  {
214  s << "\n" << header.first << " : " << header.second;
215  }
216  return s;
217  }
218 
219  } // namespace Client
220 } // namespace Aws
Aws::Client::AWSError::m_errorPayloadType
ErrorPayloadType m_errorPayloadType
Definition: AWSError.h:197
Aws::Client::AWSError::ShouldRetry
bool ShouldRetry() const
Definition: AWSError.h:133
Aws::DirectoryService::Model::LDAPSType::NOT_SET
@ NOT_SET
Aws::Client::AWSError::m_isRetryable
bool m_isRetryable
Definition: AWSError.h:195
Aws::Client::AWSError::SetRemoteHostIpAddress
void SetRemoteHostIpAddress(const Aws::String &remoteHostIpAddress)
Definition: AWSError.h:119
Aws::Client::AWSError::GetErrorPayloadType
ErrorPayloadType GetErrorPayloadType()
Definition: AWSError.h:156
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:188
Aws::Client::AWSError::SetResponseHeaders
void SetResponseHeaders(const Aws::Http::HeaderValueCollection &headers)
Definition: AWSError.h:141
Aws::Client::AWSError::SetXmlPayload
void SetXmlPayload(const Aws::Utils::Xml::XmlDocument &xmlPayload)
Definition: AWSError.h:157
Aws::Client::AWSError::GetErrorType
const ERROR_TYPE GetErrorType() const
Definition: AWSError.h:93
Aws::Client::AWSError::SetMessage
void SetMessage(const Aws::String &message)
Definition: AWSError.h:109
Aws::Client::AWSError::GetXmlPayload
const Aws::Utils::Xml::XmlDocument & GetXmlPayload() const
Definition: AWSError.h:167
Aws::Client::AWSError::operator=
AWSError & operator=(const AWSError< ERROR_TYPE > &)=default
Aws::Client::AWSError::m_responseCode
Aws::Http::HttpResponseCode m_responseCode
Definition: AWSError.h:194
Aws::Http::HttpResponseCode
HttpResponseCode
Definition: HttpResponse.h:30
Aws::Client::AWSError::AWSError
AWSError(ERROR_TYPE errorType, bool isRetryable)
Definition: AWSError.h:55
Aws::Client::AWSError::ResponseHeaderExists
bool ResponseHeaderExists(const Aws::String &headerName) const
Definition: AWSError.h:145
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:162
Aws::Client::AWSError::GetResponseCode
Aws::Http::HttpResponseCode GetResponseCode() const
Definition: AWSError.h:149
Aws::Client::AWSError::AWSError
AWSError(AWSError &&)=default
Aws::Client::AWSError::m_requestId
Aws::String m_requestId
Definition: AWSError.h:192
Aws::Client::AWSError::m_message
Aws::String m_message
Definition: AWSError.h:190
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:48
Aws::Client::AWSError::SetExceptionName
void SetExceptionName(const Aws::String &exceptionName)
Definition: AWSError.h:101
Aws::Client::AWSError::GetResponseHeaders
const Aws::Http::HeaderValueCollection & GetResponseHeaders() const
Definition: AWSError.h:137
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:182
Aws::Client::AWSError::GetExceptionName
const Aws::String & GetExceptionName() const
Definition: AWSError.h:97
Aws::Client::AWSError::SetRequestId
void SetRequestId(const Aws::String &requestId)
Definition: AWSError.h:129
Aws::Client::AWSError::GetRequestId
const Aws::String & GetRequestId() const
Definition: AWSError.h:125
XmlSerializer.h
Aws::Client::AWSError::AWSError
AWSError(AWSError< OTHER_ERROR_TYPE > &&rhs)
Definition: AWSError.h:63
AWSString.h
Aws::Utils::Json::JsonValue
Definition: JsonSerializer.h:30
Aws::Client::AWSError
Definition: AWSError.h:35
HttpResponse.h
Aws::Utils::Xml::XmlDocument
Definition: XmlSerializer.h:156
StringUtils.h
Aws::Client::AWSError::m_remoteHostIpAddress
Aws::String m_remoteHostIpAddress
Definition: AWSError.h:191
Aws::Client::ErrorPayloadType::NOT_SET
@ NOT_SET
Aws::Client::AWSError::m_responseHeaders
Aws::Http::HeaderValueCollection m_responseHeaders
Definition: AWSError.h:193
Core_EXPORTS.h
Aws
Definition: AccessManagementClient.h:15
Aws::Client::AWSError::SetJsonPayload
void SetJsonPayload(Aws::Utils::Json::JsonValue &&jsonPayload)
Definition: AWSError.h:177
Aws::Client::AWSError::GetRemoteHostIpAddress
const Aws::String & GetRemoteHostIpAddress() const
Definition: AWSError.h:115
Aws::Client::AWSError::m_jsonPayload
Aws::Utils::Json::JsonValue m_jsonPayload
Definition: AWSError.h:199
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:203
Aws::Client::AWSError::m_xmlPayload
Aws::Utils::Xml::XmlDocument m_xmlPayload
Definition: AWSError.h:198
Aws::Client::AWSError::m_exceptionName
Aws::String m_exceptionName
Definition: AWSError.h:189
Aws::Client::ErrorPayloadType
ErrorPayloadType
Definition: AWSError.h:24
Aws::Client::AWSError::AWSError
AWSError()
Definition: AWSError.h:44
Aws::Client::AWSError::SetJsonPayload
void SetJsonPayload(const Aws::Utils::Json::JsonValue &jsonPayload)
Definition: AWSError.h:172
Aws::Client::AWSError::GetMessage
const Aws::String & GetMessage() const
Definition: AWSError.h:105
Aws::Client::AWSError::SetResponseCode
void SetResponseCode(Aws::Http::HttpResponseCode responseCode)
Definition: AWSError.h:153
JsonSerializer.h
Aws::Client::AWSError::AWSError
AWSError(const AWSError< OTHER_ERROR_TYPE > &rhs)
Definition: AWSError.h:72
Aws::Utils::StringUtils::ToLower
static Aws::String ToLower(const char *source)