Microsoft Information Protection (MIP) SDK for C++: Reference 1.16
Doxygen-generated documentation for MIP SDK written in C++
Loading...
Searching...
No Matches
NetworkError Class Referenceabstract

Networking error. Caused by unexpected behavior when making network calls to service endpoints. More...

#include <src/api/mip/error.h>

Inheritance diagram for NetworkError:
Collaboration diagram for NetworkError:

Public Types

enum class  Category {
  Unknown = 0 , FailureResponseCode = 1 , BadResponse = 2 , UnexpectedResponse = 3 ,
  NoConnection = 4 , Proxy = 5 , SSL = 6 , Timeout = 7 ,
  Offline = 8 , Throttled = 9 , Cancelled = 10 , FunctionNotImplemented = 11 ,
  ServiceUnavailable = 12
}
 Category of network error. More...
 

Public Member Functions

void AddDebugInfo (const std::string &key, const std::string &value, bool sensitive=false)
 Add debug info entry.
 
virtual std::shared_ptr< ErrorClone () const =0
 Clone the error.
 
Category GetCategory () const
 Gets the category of network failure.
 
const std::map< std::string, std::string > & GetDebugInfo () const
 Get debug info.
 
const std::string & GetErrorName () const
 Get the error name.
 
virtual ErrorType GetErrorType () const
 Get the error type.
 
const std::string & GetMessage (bool maskPII=false) const
 Get the error message.
 
int32_t GetResponseStatusCode () const
 Gets the HTTP response status code.
 
void SetMessage (const std::string &msg)
 Set the error message.
 
char const * what () const noexcept override
 Get the error message.
 

Public Attributes

std::map< std::string, std::string > mDebugInfo
 
std::string mMessage
 
std::string mName
 
ErrorType mType
 

Private Member Functions

std::string CreateFormattedMessage (const std::string &message) const
 
const std::string & GetCategoryString (Category category) const
 

Private Attributes

Category mCategory
 
std::string mFormattedMessage
 
std::string mMaskedMessage
 
int32_t mResponseStatusCode
 

Detailed Description

Networking error. Caused by unexpected behavior when making network calls to service endpoints.

Definition at line 462 of file error.h.

Member Enumeration Documentation

◆ Category

enum class NetworkError::Category
strong

Category of network error.

Enumerator
Unknown 

Unknown network failure

FailureResponseCode 

HTTP response code indicates failure

BadResponse 

HTTP response could not be read

UnexpectedResponse 

HTTP response completed but contained unexpected data

NoConnection 

Failed to establish a connection

Proxy 

Proxy failure

SSL 

SSL failure

Timeout 

Connection timed out

Offline 

Operation requires network connectivity

Throttled 

HTTP operation failed due to server traffic throttling

Cancelled 

HTTP operation has been cancelled by the application

FunctionNotImplemented 

HTTP response code indicates called function is not implemented

ServiceUnavailable 

HTTP response code indicates service is unavailable

Definition at line 467 of file error.h.

467 {
468 Unknown = 0, /**< Unknown network failure */
469 FailureResponseCode = 1, /**< HTTP response code indicates failure */
470 BadResponse = 2, /**< HTTP response could not be read */
471 UnexpectedResponse = 3, /**< HTTP response completed but contained unexpected data */
472 NoConnection = 4, /**< Failed to establish a connection */
473 Proxy = 5, /**< Proxy failure */
474 SSL = 6, /**< SSL failure */
475 Timeout = 7, /**< Connection timed out */
476 Offline = 8, /**< Operation requires network connectivity */
477 Throttled = 9, /**< HTTP operation failed due to server traffic throttling */
478 Cancelled = 10, /**< HTTP operation has been cancelled by the application */
479 FunctionNotImplemented = 11, /**< HTTP response code indicates called function is not implemented */
480 ServiceUnavailable = 12, /**< HTTP response code indicates service is unavailable */
481 };

Member Function Documentation

◆ AddDebugInfo()

void Error::AddDebugInfo ( const std::string & key,
const std::string & value,
bool sensitive = false )
inlineinherited

Add debug info entry.

Parameters
keyDebug info key
valueDebug info value

Definition at line 179 of file error.h.

179 {
180 if (!key.empty() && !value.empty()) {
181 mDebugInfo[key] = value;
182 mFormattedMessage = mFormattedMessage + ", " + key + "=" + value;
183 mMaskedMessage = mMaskedMessage + ", " + key + "=" + (sensitive ? "***" : value);
184 }
185 }
std::map< std::string, std::string > mDebugInfo
Definition error.h:225
std::string mMaskedMessage
Definition error.h:241
std::string mFormattedMessage
Definition error.h:240

References Error::mDebugInfo, Error::mFormattedMessage, and Error::mMaskedMessage.

Referenced by NoPermissionsExtendedError::AddExtendedErrorInfoToDebugInfo(), DelegateResponseError::DelegateResponseError(), DelegateResponseError::DelegateResponseError(), and DelegateResponseError::DelegateResponseError().

◆ Clone()

virtual std::shared_ptr< Error > Error::Clone ( ) const
pure virtualinherited

Clone the error.

Returns
a clone of the error.

Implemented in JustificationRequiredError.

◆ CreateFormattedMessage()

std::string Error::CreateFormattedMessage ( const std::string & message) const
inlineprivateinherited

Definition at line 230 of file error.h.

230 {
231 auto formattedMessage = message;
232
233 // Remove stray newlines
234 auto isNewlineFn = [](char c) { return c == '\n' || c == '\r'; };
235 formattedMessage.erase(std::remove_if(formattedMessage.begin(), formattedMessage.end(), isNewlineFn), formattedMessage.end());
236
237 return formattedMessage;
238 }

◆ GetCategory()

Category NetworkError::GetCategory ( ) const
inline

Gets the category of network failure.

Returns
Category of network failure

Definition at line 523 of file error.h.

523{ return mCategory; }
Category mCategory
Definition error.h:533

References mCategory.

◆ GetCategoryString()

const std::string & NetworkError::GetCategoryString ( Category category) const
inlineprivate

Definition at line 536 of file error.h.

536 {
537 static const std::string kUnrecognized = "UNRECOGNIZED";
538 static const std::map<Category, std::string> kCategories = {
539 { Category::Unknown, "Unknown" },
540 { Category::FailureResponseCode, "FailureResponseCode" },
541 { Category::BadResponse, "BadResponse" },
542 { Category::UnexpectedResponse, "UnexpectedResponse" },
543 { Category::NoConnection, "NoConnection" },
544 { Category::Proxy, "Proxy" },
545 { Category::SSL, "SSL" },
546 { Category::Timeout, "Timeout" },
547 { Category::Offline, "Offline" },
548 { Category::Throttled, "Throttled" },
549 { Category::ServiceUnavailable, "ServiceUnavailable" },
550 { Category::Cancelled, "Cancelled" },
551 };
552 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
553 }

References BadResponse, Cancelled, FailureResponseCode, NoConnection, Offline, Proxy, ServiceUnavailable, SSL, Throttled, Timeout, UnexpectedResponse, and Unknown.

◆ GetDebugInfo()

const std::map< std::string, std::string > & Error::GetDebugInfo ( ) const
inlineinherited

Get debug info.

Returns
Debug info (keys/values)

Definition at line 192 of file error.h.

192{ return mDebugInfo; }

References Error::mDebugInfo.

◆ GetErrorName()

const std::string & Error::GetErrorName ( ) const
inlineinherited

Get the error name.

Returns
the error name.

Definition at line 144 of file error.h.

144{ return mName; }
std::string mName
Definition error.h:226

References Error::mName.

◆ GetErrorType()

virtual ErrorType Error::GetErrorType ( ) const
inlinevirtualinherited

Get the error type.

Returns
the error type.

Definition at line 137 of file error.h.

137{ return mType; }
ErrorType mType
Definition error.h:227

References Error::mType.

◆ GetMessage()

const std::string & Error::GetMessage ( bool maskPII = false) const
inlineinherited

Get the error message.

Returns
the error message.

Definition at line 151 of file error.h.

151 {
152 return maskPII ? mMaskedMessage : mFormattedMessage;
153 }

References Error::mFormattedMessage, and Error::mMaskedMessage.

◆ GetResponseStatusCode()

int32_t NetworkError::GetResponseStatusCode ( ) const
inline

Gets the HTTP response status code.

Returns
HTTP response status code, 0 if none

Definition at line 530 of file error.h.

530{ return mResponseStatusCode; }
int32_t mResponseStatusCode
Definition error.h:534

References mResponseStatusCode.

◆ SetMessage()

void Error::SetMessage ( const std::string & msg)
inlineinherited

Set the error message.

Parameters
msgthe error message.

Definition at line 160 of file error.h.

160 {
161 std::string* targetStrings[] = { &mFormattedMessage, &mMaskedMessage };
162 for (auto* targetString : targetStrings) {
163 size_t pos = targetString->find(mMessage);
164 if (pos != std::string::npos) {
165 targetString->replace(pos, mMessage.length(), msg);
166 } else {
167 targetString->replace(0, 0, msg);
168 }
169 }
170 mMessage = msg;
171 }
std::string mMessage
Definition error.h:224

References Error::mFormattedMessage, Error::mMaskedMessage, and Error::mMessage.

◆ what()

char const * Error::what ( ) const
inlineoverridenoexceptinherited

Get the error message.

Returns
the error message

Definition at line 121 of file error.h.

121 {
122 return mFormattedMessage.c_str();
123 }

References Error::mFormattedMessage.

Member Data Documentation

◆ mCategory

Category NetworkError::mCategory
private

Definition at line 533 of file error.h.

Referenced by GetCategory().

◆ mDebugInfo

std::map<std::string, std::string> Error::mDebugInfo
inherited

Definition at line 225 of file error.h.

Referenced by Error::AddDebugInfo(), and Error::GetDebugInfo().

◆ mFormattedMessage

std::string Error::mFormattedMessage
privateinherited

Definition at line 240 of file error.h.

Referenced by Error::AddDebugInfo(), Error::GetMessage(), Error::SetMessage(), and Error::what().

◆ mMaskedMessage

std::string Error::mMaskedMessage
privateinherited

Definition at line 241 of file error.h.

Referenced by Error::AddDebugInfo(), Error::GetMessage(), and Error::SetMessage().

◆ mMessage

std::string Error::mMessage
inherited

Definition at line 224 of file error.h.

Referenced by DelegateResponseError::DelegateResponseError(), and Error::SetMessage().

◆ mName

std::string Error::mName
inherited

Definition at line 226 of file error.h.

Referenced by Error::GetErrorName().

◆ mResponseStatusCode

int32_t NetworkError::mResponseStatusCode
private

Definition at line 534 of file error.h.

Referenced by GetResponseStatusCode().

◆ mType

ErrorType Error::mType
inherited

Definition at line 227 of file error.h.

Referenced by Error::GetErrorType().


The documentation for this class was generated from the following file: