azure-core
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
9#pragma once
10
13
14#include <memory>
15#include <stdexcept>
16#include <string>
17#include <vector>
18
19namespace Azure { namespace Core {
57 class RequestFailedException : public std::runtime_error {
58 public:
63 std::unique_ptr<Azure::Core::Http::RawResponse> RawResponse;
64
69 Azure::Core::Http::HttpStatusCode StatusCode = Azure::Core::Http::HttpStatusCode::None;
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),
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
179 ~RequestFailedException() override = default;
180
181 private:
182 static std::string GetRawResponseField(
183 std::unique_ptr<Azure::Core::Http::RawResponse> const& rawResponse,
184 std::string const& fieldName);
185
189 static std::string GetRawResponseErrorMessage(
190 std::unique_ptr<Azure::Core::Http::RawResponse> const& rawResponse);
191 };
192}} // namespace Azure::Core
An error while trying to send a request to Azure service.
Definition exception.hpp:57
Azure::Core::Http::HttpStatusCode StatusCode
The HTTP response code.
Definition exception.hpp:69
RequestFailedException & operator=(RequestFailedException &&)=delete
An instance of RequestFailedException class cannot be moved into another instance after creation.
RequestFailedException(const RequestFailedException &other)
Constructs a new RequestFailedException by copying from an existing one.
Definition exception.hpp:144
std::string Message
The error message from the service returned in the HTTP response.
Definition exception.hpp:112
std::unique_ptr< Azure::Core::Http::RawResponse > RawResponse
The entire HTTP raw response.
Definition exception.hpp:63
std::string ErrorCode
The error code from service returned in the HTTP response.
Definition exception.hpp:99
RequestFailedException & operator=(const RequestFailedException &)=delete
An instance of RequestFailedException class cannot be assigned.
~RequestFailedException() override=default
Destructs RequestFailedException.
std::string RequestId
The request ID header (x-ms-request-id) from the HTTP response.
Definition exception.hpp:87
std::string ClientRequestId
The client request header (x-ms-client-request-id) from the HTTP response.
Definition exception.hpp:81
std::string ReasonPhrase
The HTTP reason phrase from the response.
Definition exception.hpp:75
RequestFailedException(RequestFailedException &&other)=default
Constructs a new RequestFailedException by moving in an existing one.
HTTP status code definition.
HttpStatusCode
Defines the possible HTTP status codes.
Definition http_status_code.hpp:18
Compute the hash value for the input binary data, using SHA256, SHA384 and SHA512.
Definition azure_assert.hpp:57
Define the HTTP raw response.