33#ifndef API_MIP_ERROR_H_
34#define API_MIP_ERROR_H_
50constexpr const char* GetStackTraceString() {
54constexpr const char* GetHResultString() {
58constexpr const char* GetBadInputErrorString() {
59 return "BadInputError";
62constexpr const char* GetNoPermissionsExtendedErrorName() {
return "NoPermissionsExtendedError"; }
64constexpr const char* GetErrorInfoCodesKey() {
return "ExtendedErrorInfo_Codes"; }
66constexpr const char* GetErrorInfoMessagesKey() {
return "ExtendedErrorInfo_Messages"; }
68constexpr const char* GetErrorInfoDetailsKey() {
return "ExtendedErrorInfo_Details"; }
116class Error :
public std::exception {
123 char const*
what() const noexcept
override {
132 virtual std::shared_ptr<Error>
Clone()
const = 0;
164 for (
auto* targetString : targetStrings) {
165 size_t pos = targetString->find(
mMessage);
166 if (pos != std::string::npos) {
167 targetString->replace(pos,
mMessage.length(), msg);
169 targetString->replace(0, 0, msg);
181 void AddDebugInfo(
const std::string& key,
const std::string& value,
bool sensitive =
false) {
182 if (!key.empty() && !value.empty()) {
201 const std::string& message,
202 const std::string& name,
209 const std::string& message,
210 const std::map<std::string, std::string> debugInfo,
211 const std::map<std::string, std::string> sensitiveDebugInfo,
212 const std::string& name,
217 for (
const auto& entry: sensitiveDebugInfo) {
220 for (
const auto& entry: debugInfo) {
233 auto formattedMessage = message;
236 auto isNewlineFn = [](
char c) {
return c ==
'\n' || c ==
'\r'; };
237 formattedMessage.erase(std::remove_if(formattedMessage.begin(), formattedMessage.end(), isNewlineFn), formattedMessage.end());
239 return formattedMessage;
266 const std::string& message,
267 const std::string& name = GetBadInputErrorString(),
272 const std::string& message,
274 const std::string& name = GetBadInputErrorString())
278 const std::string& message,
279 const std::map<std::string, std::string>& debugInfo,
280 const std::map<std::string, std::string> sensitiveDebugInfo,
281 const std::string& name = GetBadInputErrorString(),
287 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<BadInputError>(*
this); }
301 static const std::string kUnrecognized =
"UNRECOGNIZED";
302 static const std::map<ErrorCode, std::string> kCodes = {
310 return kCodes.count(code) ? kCodes.at(code) : kUnrecognized;
327 mCurrentException(except) {
330 std::rethrow_exception(except);
331 }
catch(
const Error& error) {
332 *
static_cast<Error*
>(
this) = error;
333 }
catch (
const std::exception& thisException) {
334 this->
mMessage = std::string(thisException.what());
348 const std::string& message,
349 const std::string& stackTrace,
350 const std::string& name =
"DelegateResponseError")
365 const std::string& message,
367 const std::string& stackTrace,
368 const std::string& name =
"DelegateResponseError")
370 std::stringstream hrStream;
371 hrStream << std::hex << HResult;
385 std::stringstream hrStream;
386 hrStream << std::hex << HResult;
405 std::shared_ptr<Error>
Clone()
const override {
407 auto result = std::make_shared<mip::DelegateResponseError>(*
this);
408 return std::static_pointer_cast<Error>(result);
413 const std::exception_ptr& GetExceptionPtr()
const {
return mCurrentException; }
416 std::exception_ptr mCurrentException;
427 const std::string& message,
428 const std::string& name =
"InsufficientBufferError")
431 const std::string& message,
432 const std::map<std::string, std::string>& debugInfo,
433 const std::map<std::string, std::string> sensitiveDebugInfo,
434 const std::string& name =
"InsufficientBufferError")
435 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
436 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<InsufficientBufferError>(*
this); }
448 const std::string& message,
449 const std::string& name =
"FileIOError")
452 const std::string& message,
453 const std::map<std::string, std::string>& debugInfo,
454 const std::map<std::string, std::string> sensitiveDebugInfo,
455 const std::string& name =
"FileIOError")
457 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<FileIOError>(*
this); }
488 const std::string& sanitizedUrl,
489 const std::string& requestId,
491 const std::string& message,
492 const std::string& name =
"NetworkError")
493 :
NetworkError(category, sanitizedUrl, requestId, statusCode, message, {{}}, {{}}, name) {}
497 const std::string& sanitizedUrl,
498 const std::string& requestId,
500 const std::string& message,
501 const std::map<std::string, std::string>& debugInfo,
502 const std::map<std::string, std::string> sensitiveDebugInfo,
503 const std::string& name =
"NetworkError")
504 :
NetworkError(category, statusCode, message, debugInfo, sensitiveDebugInfo, name) {
505 if (!sanitizedUrl.empty())
507 if (!requestId.empty())
514 const std::string& message,
515 const std::map<std::string, std::string>& debugInfo,
516 const std::map<std::string, std::string> sensitiveDebugInfo,
517 const std::string& name =
"NetworkError")
523 AddDebugInfo(
"HttpResponse.StatusCode", std::to_string(
static_cast<int>(statusCode)));
526 std::shared_ptr<Error>
Clone()
const override {
527 return std::make_shared<NetworkError>(*
this);
550 static const std::string kUnrecognized =
"UNRECOGNIZED";
551 static const std::map<Category, std::string> kCategories = {
565 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
576 const std::string& sanitizedUrl,
577 const std::string& requestId,
579 const std::string& message,
580 const std::string& name =
"ProxyAuthenticationError")
584 const std::string& message,
585 const std::map<std::string, std::string>& debugInfo,
586 const std::map<std::string, std::string> sensitiveDebugInfo,
587 const std::string& name =
"ProxyAuthenticationError")
589 std::shared_ptr<Error>
Clone()
const override {
590 return std::make_shared<ProxyAuthenticationError>(*
this);
603 const std::string& message,
604 const std::string& name =
"InternalError")
607 const std::string& message,
608 const std::map<std::string, std::string>& debugInfo,
609 const std::map<std::string, std::string> sensitiveDebugInfo,
610 const std::string& name =
"InternalError")
612 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<InternalError>(*
this); }
623 const std::string& message,
624 const std::string& name =
"NotSupportedError")
627 const std::string& message,
628 const std::map<std::string, std::string>& debugInfo,
629 const std::map<std::string, std::string> sensitiveDebugInfo,
630 const std::string& name =
"NotSupportedError")
633 const std::string& message,
635 const std::string& name =
"NotSupportedError")
636 :
Error(message, name, errorType) {}
637 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NotSupportedError>(*
this); }
649 const std::string& message,
650 const std::string& name =
"PrivilegedRequiredError")
653 const std::string& message,
654 const std::map<std::string, std::string>& debugInfo,
655 const std::map<std::string, std::string> sensitiveDebugInfo,
656 const std::string& name =
"PrivilegedRequiredError")
658 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<PrivilegedRequiredError>(*
this); }
669 const std::string& message,
670 const std::string& name =
"AccessDeniedError")
673 const std::string& message,
674 const std::map<std::string, std::string>& debugInfo,
675 const std::map<std::string, std::string> sensitiveDebugInfo,
676 const std::string& name =
"AccessDeniedError")
678 virtual std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<AccessDeniedError>(*
this); }
710 const std::string& message,
711 const std::string& referrer =
"",
712 const std::string& owner =
"",
713 const std::string& name =
"NoPermissionsError")
717 const std::string& message,
718 const std::string& referrer,
719 const std::string& owner,
720 const std::map<std::string, std::string>& debugInfo,
721 const std::map<std::string, std::string> sensitiveDebugInfo,
722 const std::string& name =
"NoPermissionsError")
725 if (!referrer.empty())
726 AddDebugInfo(
"NoPermissionsError.Referrer", referrer,
true);
730#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
734 const std::string& message,
735 const std::string& referrer,
736 const std::string& owner,
737 const std::string& name =
"NoPermissionsError")
739#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
743 const std::string& message,
744 const std::string& referrer,
745 const std::string& owner,
746 const std::map<std::string, std::string>& debugInfo,
747 const std::map<std::string, std::string> sensitiveDebugInfo,
748 const std::string& name =
"NoPermissionsError")
750 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoPermissionsError>(*
this); }
781 static const std::string kUnrecognized =
"UNRECOGNIZED";
782 static const std::map<Category, std::string> kCategories = {
796 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
807 const std::string& message,
808 const std::string& referrer,
809 const std::string& owner,
810 const std::vector<ExtendedErrorInfo>& extendedErrorInfo,
811 const std::string& name = GetNoPermissionsExtendedErrorName())
816 const std::string& message,
817 const std::string& referrer,
818 const std::string& owner,
819 const std::map<std::string, std::string> debugInfo,
820 const std::map<std::string, std::string> sensitiveDebugInfo,
821 const std::vector<ExtendedErrorInfo>& extendedErrorInfo,
822 const std::string& name = GetNoPermissionsExtendedErrorName())
823 :
NoPermissionsError(category, message, referrer, owner, debugInfo, sensitiveDebugInfo, name),
826 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoPermissionsExtendedError>(*
this); }
828 std::vector<ExtendedErrorInfo> GetExtendedErrorInfo()
const {
835 std::stringstream codesStream;
836 std::stringstream messagesStream;
837 std::stringstream detailsStream;
839 static const std::string seperator =
",";
840 static const std::string objSeperator =
";";
841 static const std::string mapElementSeperator =
"|";
842 for (
size_t i = 0; i < extendedErrorInfo.size(); i++) {
843 codesStream << extendedErrorInfo[i].code;
844 messagesStream << extendedErrorInfo[i].message;
845 std::map<std::string, std::string>::const_iterator detailsIter = extendedErrorInfo[i].details.begin();
846 while (detailsIter != extendedErrorInfo[i].details.end()) {
847 detailsStream << detailsIter->first << seperator << detailsIter->second;
849 if (detailsIter != extendedErrorInfo[i].details.end()) {
850 detailsStream << mapElementSeperator;
854 if (i + 1 < extendedErrorInfo.size()) {
855 codesStream << objSeperator;
856 messagesStream << objSeperator;
857 detailsStream << objSeperator;
861 if (!extendedErrorInfo.empty()) {
862 AddDebugInfo(GetErrorInfoCodesKey(), codesStream.str());
863 AddDebugInfo(GetErrorInfoMessagesKey(), messagesStream.str());
864 AddDebugInfo(GetErrorInfoDetailsKey(), detailsStream.str());
878 const std::string& message,
879 const std::string& name =
"NoAuthTokenError")
882 const std::string& message,
883 const std::map<std::string, std::string>& debugInfo,
884 const std::map<std::string, std::string> sensitiveDebugInfo,
885 const std::string& name =
"NoAuthTokenError")
887 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoAuthTokenError>(*
this); }
910 const std::string& requestId,
911 const std::string& message,
912 const std::string& name =
"ServiceDisabledError")
914 if (!requestId.empty())
919 const std::string& message,
920 const std::map<std::string, std::string>& debugInfo,
921 const std::map<std::string, std::string> sensitiveDebugInfo,
922 const std::string& name =
"ServiceDisabledError")
928 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<ServiceDisabledError>(*
this); }
941 static const std::string kUnrecognized =
"UNRECOGNIZED";
942 static const std::map<Extent, std::string> kExtents = {
948 return kExtents.count(extent) ? kExtents.at(extent) : kUnrecognized;
961 const std::string& message,
962 const std::string& name =
"ConsentDeniedError")
965 const std::string& message,
966 const std::map<std::string, std::string>& debugInfo,
967 const std::map<std::string, std::string> sensitiveDebugInfo,
968 const std::string& name =
"ConsentDeniedError")
970 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<ConsentDeniedError>(*
this); }
984 enum class Category {
991 const std::string& message,
992 const Category category,
993 const std::string& name =
"NoPolicyError")
996 const std::string& message,
997 const Category category,
998 const std::map<std::string, std::string>& debugInfo,
999 const std::map<std::string, std::string> sensitiveDebugInfo,
1000 const std::string& name =
"NoPolicyError")
1002 mCategory(category) {
1003 AddDebugInfo(
"NoPolicyError.Category", GetCategoryString(category));
1006 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoPolicyError>(*
this); }
1007 Category GetCategory()
const {
return mCategory; }
1009 const std::string& GetCategoryString(Category category)
const {
1010 static const std::string kUnrecognized =
"UNRECOGNIZED";
1011 static const std::map<Category, std::string> kCategories = {
1012 { Category::SyncFile,
"SyncFile" },
1013 { Category::Labels,
"Labels" },
1014 { Category::Rules,
"Rules" },
1016 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
1030 const std::string& message,
1031 const std::string& name =
"OperationCancelledError")
1034 const std::string& message,
1035 const std::map<std::string, std::string>& debugInfo,
1036 const std::map<std::string, std::string> sensitiveDebugInfo,
1037 const std::string& name =
"OperationCancelledError")
1039 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<OperationCancelledError>(*
this); }
1050 const std::string& message,
1051 const std::string& name =
"AdhocProtectionRequiredError")
1054 const std::string& message,
1055 const std::map<std::string, std::string>& debugInfo,
1056 const std::map<std::string, std::string> sensitiveDebugInfo,
1057 const std::string& name =
"AdhocProtectionRequiredError")
1059 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<AdhocProtectionRequiredError>(*
this); }
1070 const std::string& message,
1071 const std::string& name =
"DeprecatedApiError")
1074 const std::string& message,
1075 const std::map<std::string, std::string>& debugInfo,
1076 const std::map<std::string, std::string> sensitiveDebugInfo,
1077 const std::string& name =
"DeprecatedApiError")
1079 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<DeprecatedApiError>(*
this); }
1090 const std::string& message,
1091 const std::string& name =
"TemplateNotFoundError")
1094 const std::string& message,
1095 const std::map<std::string, std::string>& debugInfo,
1096 const std::map<std::string, std::string> sensitiveDebugInfo,
1097 const std::string& name =
"TemplateNotFoundError")
1098 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1100 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<TemplateNotFoundError>(*
this); }
1112 const std::string& message,
1113 const std::string& name =
"TemplateArchivedError")
1116 const std::string& message,
1117 const std::map<std::string, std::string>& debugInfo,
1118 const std::map<std::string, std::string> sensitiveDebugInfo,
1119 const std::string& name =
"TemplateArchivedError")
1120 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1122 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<TemplateArchivedError>(*
this); }
1134 const std::string& message,
1135 const std::string& name =
"ContentFormatNotSupportedError")
1138 const std::string& message,
1139 const std::map<std::string, std::string>& debugInfo,
1140 const std::map<std::string, std::string> sensitiveDebugInfo,
1141 const std::string& name =
"ContentFormatNotSupportedError")
1142 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1144 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<ContentFormatNotSupportedError>(*
this); }
1156 const std::string& message,
1157 const std::string& name =
"LabelNotFoundError")
1160 const std::string& message,
1161 const std::map<std::string, std::string>& debugInfo,
1162 const std::map<std::string, std::string> sensitiveDebugInfo,
1163 const std::string& name =
"LabelNotFoundError")
1164 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1166 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<LabelNotFoundError>(*
this); }
1178 const std::string& message,
1179 const std::string& name =
"LicenseNotRegisteredError")
1182 const std::string& message,
1183 const std::map<std::string, std::string>& debugInfo,
1184 const std::map<std::string, std::string> sensitiveDebugInfo,
1185 const std::string& name =
"LicenseNotRegisteredError")
1186 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1188 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<LicenseNotRegisteredError>(*
this); }
1200 const std::string& message,
1201 const std::string& name =
"LabelDisabledError")
1204 const std::string& message,
1205 const std::map<std::string, std::string>& debugInfo,
1206 const std::map<std::string, std::string> sensitiveDebugInfo,
1207 const std::string& name =
"LabelDisabledError")
1208 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1209 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<LabelDisabledError>(*
this); }
1221 const std::string& message,
1222 const std::string& name =
"CustomerKeyUnavailableError")
1225 const std::string& message,
1226 const std::map<std::string, std::string>& debugInfo,
1227 const std::map<std::string, std::string>& sensitiveDebugInfo,
1228 const std::string& name =
"CustomerKeyUnavailableError")
1230 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<CustomerKeyUnavailableError>(*
this); }
1243 const std::string& message,
1244 const std::string& name =
"MaxDepthReachedError")
1247 const std::string& message,
1248 const std::map<std::string, std::string>& debugInfo,
1249 const std::map<std::string, std::string> sensitiveDebugInfo,
1250 const std::string& name =
"MaxDepthReachedError")
1252 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<MaxDepthReachedError>(*
this); }
The user could not get access to the content. For example, no permissions, content revoked.
Definition error.h:665
Adhoc protection should be set to complete the action on the file.
Definition error.h:1046
An operation that required consent from user was not granted consent.
Definition error.h:957
Content Format is not supported.
Definition error.h:1130
Bring your own encryption key needed and unavailable.
Definition error.h:1217
Delegate Response Error. Thrown or returned in response to encountering an error in a delegate method...
Definition error.h:317
DelegateResponseError(const std::exception_ptr &except)
Creates an error/exception object. Call this method from a MIP delegate function to create a MIP or s...
Definition error.h:325
DelegateResponseError(const std::string &message, const std::string &stackTrace, const std::string &name="DelegateResponseError")
Creates an error/exception object. Call this method from a MIP delegate function to create a generic ...
Definition error.h:347
DelegateResponseError(const std::string &message, long HResult, const std::string &stackTrace, const std::string &name="DelegateResponseError")
Creates an error/exception object. Call this method from a MIP delegate function to create a generic ...
Definition error.h:364
DelegateResponseError(const std::string &message)
Creates an error/exception object. Call this method from a MIP delegate function to create a generic ...
Definition error.h:396
DelegateResponseError(const std::string &message, long HResult)
Creates an error/exception object. Call this method from a MIP delegate function to create a generic ...
Definition error.h:383
Caller invoked a deprecated API.
Definition error.h:1066
Base class for all errors that will be reported (thrown or returned) from MIP SDK.
Definition error.h:116
std::map< std::string, std::string > mDebugInfo
Definition error.h:227
const std::string & GetMessage(bool maskPII=false) const
Get the error message.
Definition error.h:153
void AddDebugInfo(const std::string &key, const std::string &value, bool sensitive=false)
Add debug info entry.
Definition error.h:181
const std::string & GetErrorName() const
Get the error name.
Definition error.h:146
virtual std::shared_ptr< Error > Clone() const =0
Clone the error.
char const * what() const noexcept override
Get the error message.
Definition error.h:123
std::string mMaskedMessage
Definition error.h:243
std::string CreateFormattedMessage(const std::string &message) const
Definition error.h:232
std::string mName
Definition error.h:228
virtual ErrorType GetErrorType() const
Get the error type.
Definition error.h:139
std::string mFormattedMessage
Definition error.h:242
ErrorType mType
Definition error.h:229
const std::map< std::string, std::string > & GetDebugInfo() const
Get debug info.
Definition error.h:194
std::string mMessage
Definition error.h:226
void SetMessage(const std::string &msg)
Set the error message.
Definition error.h:162
File IO error.
Definition error.h:444
Insufficient buffer error.
Definition error.h:423
Internal error. This error is thrown when something unexpected happens during execution.
Definition error.h:599
Label is disabled or inactive.
Definition error.h:1196
Label ID is not recognized.
Definition error.h:1152
License is not registered.
Definition error.h:1174
Max depth reached error. This will be thrown while removing protection from MSGs/EMLs if the number o...
Definition error.h:1239
Networking error. Caused by unexpected behavior when making network calls to service endpoints.
Definition error.h:464
Category GetCategory() const
Gets the category of network failure.
Definition error.h:536
const std::string & GetCategoryString(Category category) const
Definition error.h:549
Category
Category of network error.
Definition error.h:469
Category mCategory
Definition error.h:546
int32_t mResponseStatusCode
Definition error.h:547
int32_t GetResponseStatusCode() const
Gets the HTTP response status code.
Definition error.h:543
The user could not get access to the content due to missing authentication token.
Definition error.h:874
The user could not get access to the content. For example, no permissions, content revoked.
Definition error.h:685
Category GetCategory() const
Gets the category of no permissions failure.
Definition error.h:773
std::string mOwner
Definition error.h:778
std::string GetOwner() const
Gets the owner of the document.
Definition error.h:766
std::string mReferrer
Definition error.h:777
Category
Category of no permissions error.
Definition error.h:690
@ ClientVersionNotSupported
std::string GetReferrer() const
Gets the contact in case of missing rights to the document.
Definition error.h:759
const std::string & GetCategoryString(Category category) const
Definition error.h:780
Category mCategory
Definition error.h:776
The user could not get access to the content due to extended Access checks like ABAC.
Definition error.h:803
void AddExtendedErrorInfoToDebugInfo(const std::vector< ExtendedErrorInfo > &extendedErrorInfo)
Definition error.h:834
std::vector< ExtendedErrorInfo > mExtendedErrorInfo
Definition error.h:868
Tenant policy is not configured for classification/labels.
Definition error.h:977
The operation requested by the application is not supported by the SDK.
Definition error.h:619
Operation was cancelled.
Definition error.h:1026
Current label was assigned as a privileged operation (The equivalent to an administrator operation),...
Definition error.h:645
Proxy authentication failure.
Definition error.h:572
The user could not get access to the content due to a service being disabled.
Definition error.h:895
Extent
Describes the extent for which the service is disabled.
Definition error.h:900
Extent mExtent
Definition error.h:951
const std::string & GetExtentString(Extent extent) const
Definition error.h:940
Extent GetExtent() const
Gets the extent for which the service is disabled.
Definition error.h:937
Template ID is archived and unavailable for protection.
Definition error.h:1108
Template ID is not recognized by RMS service.
Definition error.h:1086
A file Containing the common types used by the upe, file and protection modules.
ErrorType
Definition error.h:74
@ ADHOC_PROTECTION_REQUIRED
@ CONTENT_FORMAT_NOT_SUPPORTED
@ CUSTOMER_KEY_UNAVAILABLE
@ NOT_SUPPORTED_OPERATION
@ INSUFFICIENT_BUFFER_ERROR
std::string code
Definition error.h:108
std::map< std::string, std::string > details
Definition error.h:110
std::string message
Definition error.h:109