azure-core
exception.hpp
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // SPDX-License-Identifier: MIT
3 
9 #pragma once
10 
13 
14 #include <memory>
15 #include <stdexcept>
16 #include <string>
17 #include <vector>
18 
19 namespace Azure { namespace Core {
57  class RequestFailedException : public std::runtime_error {
58  public:
63  std::unique_ptr<Azure::Core::Http::RawResponse> RawResponse;
64 
70 
75  std::string ReasonPhrase;
76 
81  std::string ClientRequestId;
82 
87  std::string RequestId;
88 
99  std::string ErrorCode;
100 
112  std::string Message;
113 
123  explicit RequestFailedException(std::string const& what);
124 
136  explicit RequestFailedException(std::unique_ptr<Azure::Core::Http::RawResponse>& rawResponse);
137 
145  : std::runtime_error(other.Message),
146  RawResponse(
147  other.RawResponse
148  ? std::make_unique<Azure::Core::Http::RawResponse>(*other.RawResponse)
149  : nullptr),
152  ErrorCode(other.ErrorCode), Message(other.Message)
153  {
154  }
155 
161 
167 
174 
180 
181  private:
182  static std::string GetRawResponseField(
183  std::unique_ptr<Azure::Core::Http::RawResponse> const& rawResponse,
184  std::string fieldName);
185 
189  static std::string GetRawResponseErrorMessage(
190  std::unique_ptr<Azure::Core::Http::RawResponse> const& rawResponse);
191  };
192 }} // namespace Azure::Core
Azure::Core::RequestFailedException::Message
std::string Message
The error message from the service returned in the HTTP response.
Definition: exception.hpp:112
Azure::Core::RequestFailedException::RequestFailedException
RequestFailedException(std::string const &what)
Constructs a new RequestFailedException with a message string.
Definition: exception.cpp:18
Azure::Core::RequestFailedException::ErrorCode
std::string ErrorCode
The error code from service returned in the HTTP response.
Definition: exception.hpp:99
Azure::Core::RequestFailedException::StatusCode
Azure::Core::Http::HttpStatusCode StatusCode
The HTTP response code.
Definition: exception.hpp:69
Azure::Core::RequestFailedException::~RequestFailedException
~RequestFailedException()=default
Destructs RequestFailedException.
raw_response.hpp
Define the HTTP raw response.
http_status_code.hpp
HTTP status code definition.
Azure::Core::RequestFailedException::RequestFailedException
RequestFailedException(const RequestFailedException &other)
Constructs a new RequestFailedException by copying from an existing one.
Definition: exception.hpp:144
Azure::Core::RequestFailedException::operator=
RequestFailedException & operator=(const RequestFailedException &)=delete
An instance of RequestFailedException class cannot be assigned.
Azure::Core::RequestFailedException::ClientRequestId
std::string ClientRequestId
The client request header (x-ms-client-request-id) from the HTTP response.
Definition: exception.hpp:81
Azure
Azure SDK abstractions.
Definition: azure_assert.hpp:55
Azure::Core::RequestFailedException::operator=
RequestFailedException & operator=(RequestFailedException &&)=delete
An instance of RequestFailedException class cannot be moved into another instance after creation.
Azure::Core::RequestFailedException
An error while trying to send a request to Azure service.
Definition: exception.hpp:57
Azure::Core::RequestFailedException::RawResponse
std::unique_ptr< Azure::Core::Http::RawResponse > RawResponse
The entire HTTP raw response.
Definition: exception.hpp:63
Azure::Core::Http::HttpStatusCode::None
@ None
No HTTP status code.
Azure::Core::RequestFailedException::RequestFailedException
RequestFailedException(RequestFailedException &&other)=default
Constructs a new RequestFailedException by moving in an existing one.
Azure::Core::RequestFailedException::RequestId
std::string RequestId
The request ID header (x-ms-request-id) from the HTTP response.
Definition: exception.hpp:87
Azure::Core::Http::HttpStatusCode
HttpStatusCode
Defines the possible HTTP status codes.
Definition: http_status_code.hpp:18
Azure::Core::RequestFailedException::ReasonPhrase
std::string ReasonPhrase
The HTTP reason phrase from the response.
Definition: exception.hpp:75