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"; }
114class Error :
public std::exception {
121 char const*
what() const noexcept
override {
130 virtual std::shared_ptr<Error>
Clone()
const = 0;
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);
167 targetString->replace(0, 0, msg);
179 void AddDebugInfo(
const std::string& key,
const std::string& value,
bool sensitive =
false) {
180 if (!key.empty() && !value.empty()) {
199 const std::string& message,
200 const std::string& name,
207 const std::string& message,
208 const std::map<std::string, std::string> debugInfo,
209 const std::map<std::string, std::string> sensitiveDebugInfo,
210 const std::string& name,
215 for (
const auto& entry: sensitiveDebugInfo) {
218 for (
const auto& entry: debugInfo) {
231 auto formattedMessage = message;
234 auto isNewlineFn = [](
char c) {
return c ==
'\n' || c ==
'\r'; };
235 formattedMessage.erase(std::remove_if(formattedMessage.begin(), formattedMessage.end(), isNewlineFn), formattedMessage.end());
237 return formattedMessage;
264 const std::string& message,
265 const std::string& name = GetBadInputErrorString(),
270 const std::string& message,
272 const std::string& name = GetBadInputErrorString())
276 const std::string& message,
277 const std::map<std::string, std::string>& debugInfo,
278 const std::map<std::string, std::string> sensitiveDebugInfo,
279 const std::string& name = GetBadInputErrorString(),
285 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<BadInputError>(*
this); }
299 static const std::string kUnrecognized =
"UNRECOGNIZED";
300 static const std::map<ErrorCode, std::string> kCodes = {
308 return kCodes.count(code) ? kCodes.at(code) : kUnrecognized;
325 mCurrentException(except) {
328 std::rethrow_exception(except);
329 }
catch(
const Error& error) {
330 *
static_cast<Error*
>(
this) = error;
331 }
catch (
const std::exception& thisException) {
332 this->
mMessage = std::string(thisException.what());
346 const std::string& message,
347 const std::string& stackTrace,
348 const std::string& name =
"DelegateResponseError")
363 const std::string& message,
365 const std::string& stackTrace,
366 const std::string& name =
"DelegateResponseError")
368 std::stringstream hrStream;
369 hrStream << std::hex << HResult;
383 std::stringstream hrStream;
384 hrStream << std::hex << HResult;
403 std::shared_ptr<Error>
Clone()
const override {
405 auto result = std::make_shared<mip::DelegateResponseError>(*
this);
406 return std::static_pointer_cast<Error>(result);
411 const std::exception_ptr& GetExceptionPtr()
const {
return mCurrentException; }
414 std::exception_ptr mCurrentException;
425 const std::string& message,
426 const std::string& name =
"InsufficientBufferError")
429 const std::string& message,
430 const std::map<std::string, std::string>& debugInfo,
431 const std::map<std::string, std::string> sensitiveDebugInfo,
432 const std::string& name =
"InsufficientBufferError")
433 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
434 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<InsufficientBufferError>(*
this); }
446 const std::string& message,
447 const std::string& name =
"FileIOError")
450 const std::string& message,
451 const std::map<std::string, std::string>& debugInfo,
452 const std::map<std::string, std::string> sensitiveDebugInfo,
453 const std::string& name =
"FileIOError")
455 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<FileIOError>(*
this); }
486 const std::string& sanitizedUrl,
487 const std::string& requestId,
489 const std::string& message,
490 const std::string& name =
"NetworkError")
491 :
NetworkError(category, statusCode, message, {{}}, {{}}, name) {
492 if (!sanitizedUrl.empty())
494 if (!requestId.empty())
501 const std::string& message,
502 const std::map<std::string, std::string>& debugInfo,
503 const std::map<std::string, std::string> sensitiveDebugInfo,
504 const std::string& name =
"NetworkError")
510 AddDebugInfo(
"HttpResponse.StatusCode", std::to_string(
static_cast<int>(statusCode)));
513 std::shared_ptr<Error>
Clone()
const override {
514 return std::make_shared<NetworkError>(*
this);
537 static const std::string kUnrecognized =
"UNRECOGNIZED";
538 static const std::map<Category, std::string> kCategories = {
552 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
563 const std::string& sanitizedUrl,
564 const std::string& requestId,
566 const std::string& message,
567 const std::string& name =
"ProxyAuthenticationError")
571 const std::string& message,
572 const std::map<std::string, std::string>& debugInfo,
573 const std::map<std::string, std::string> sensitiveDebugInfo,
574 const std::string& name =
"ProxyAuthenticationError")
576 std::shared_ptr<Error>
Clone()
const override {
577 return std::make_shared<ProxyAuthenticationError>(*
this);
590 const std::string& message,
591 const std::string& name =
"InternalError")
594 const std::string& message,
595 const std::map<std::string, std::string>& debugInfo,
596 const std::map<std::string, std::string> sensitiveDebugInfo,
597 const std::string& name =
"InternalError")
599 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<InternalError>(*
this); }
610 const std::string& message,
611 const std::string& name =
"NotSupportedError")
614 const std::string& message,
615 const std::map<std::string, std::string>& debugInfo,
616 const std::map<std::string, std::string> sensitiveDebugInfo,
617 const std::string& name =
"NotSupportedError")
620 const std::string& message,
622 const std::string& name =
"NotSupportedError")
623 :
Error(message, name, errorType) {}
624 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NotSupportedError>(*
this); }
636 const std::string& message,
637 const std::string& name =
"PrivilegedRequiredError")
640 const std::string& message,
641 const std::map<std::string, std::string>& debugInfo,
642 const std::map<std::string, std::string> sensitiveDebugInfo,
643 const std::string& name =
"PrivilegedRequiredError")
645 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<PrivilegedRequiredError>(*
this); }
656 const std::string& message,
657 const std::string& name =
"AccessDeniedError")
660 const std::string& message,
661 const std::map<std::string, std::string>& debugInfo,
662 const std::map<std::string, std::string> sensitiveDebugInfo,
663 const std::string& name =
"AccessDeniedError")
665 virtual std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<AccessDeniedError>(*
this); }
692 const std::string& message,
693 const std::string& referrer =
"",
694 const std::string& owner =
"",
695 const std::string& name =
"NoPermissionsError")
699 const std::string& message,
700 const std::string& referrer,
701 const std::string& owner,
702 const std::map<std::string, std::string>& debugInfo,
703 const std::map<std::string, std::string> sensitiveDebugInfo,
704 const std::string& name =
"NoPermissionsError")
707 if (!referrer.empty())
708 AddDebugInfo(
"NoPermissionsError.Referrer", referrer,
true);
712#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
716 const std::string& message,
717 const std::string& referrer,
718 const std::string& owner,
719 const std::string& name =
"NoPermissionsError")
721#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
725 const std::string& message,
726 const std::string& referrer,
727 const std::string& owner,
728 const std::map<std::string, std::string>& debugInfo,
729 const std::map<std::string, std::string> sensitiveDebugInfo,
730 const std::string& name =
"NoPermissionsError")
732 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoPermissionsError>(*
this); }
763 static const std::string kUnrecognized =
"UNRECOGNIZED";
764 static const std::map<Category, std::string> kCategories = {
775 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
786 const std::string& message,
787 const std::string& referrer,
788 const std::string& owner,
789 const std::vector<ExtendedErrorInfo>& extendedErrorInfo,
790 const std::string& name = GetNoPermissionsExtendedErrorName())
795 const std::string& message,
796 const std::string& referrer,
797 const std::string& owner,
798 const std::map<std::string, std::string> debugInfo,
799 const std::map<std::string, std::string> sensitiveDebugInfo,
800 const std::vector<ExtendedErrorInfo>& extendedErrorInfo,
801 const std::string& name = GetNoPermissionsExtendedErrorName())
802 :
NoPermissionsError(category, message, referrer, owner, debugInfo, sensitiveDebugInfo, name),
805 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoPermissionsExtendedError>(*
this); }
807 std::vector<ExtendedErrorInfo> GetExtendedErrorInfo()
const {
814 std::stringstream codesStream;
815 std::stringstream messagesStream;
816 std::stringstream detailsStream;
818 static const std::string seperator =
",";
819 static const std::string objSeperator =
";";
820 static const std::string mapElementSeperator =
"|";
821 for (
size_t i = 0; i < extendedErrorInfo.size(); i++) {
822 codesStream << extendedErrorInfo[i].code;
823 messagesStream << extendedErrorInfo[i].message;
824 std::map<std::string, std::string>::const_iterator detailsIter = extendedErrorInfo[i].details.begin();
825 while (detailsIter != extendedErrorInfo[i].details.end()) {
826 detailsStream << detailsIter->first << seperator << detailsIter->second;
828 if (detailsIter != extendedErrorInfo[i].details.end()) {
829 detailsStream << mapElementSeperator;
833 if (i + 1 < extendedErrorInfo.size()) {
834 codesStream << objSeperator;
835 messagesStream << objSeperator;
836 detailsStream << objSeperator;
840 if (!extendedErrorInfo.empty()) {
841 AddDebugInfo(GetErrorInfoCodesKey(), codesStream.str());
842 AddDebugInfo(GetErrorInfoMessagesKey(), messagesStream.str());
843 AddDebugInfo(GetErrorInfoDetailsKey(), detailsStream.str());
857 const std::string& message,
858 const std::string& name =
"NoAuthTokenError")
861 const std::string& message,
862 const std::map<std::string, std::string>& debugInfo,
863 const std::map<std::string, std::string> sensitiveDebugInfo,
864 const std::string& name =
"NoAuthTokenError")
866 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoAuthTokenError>(*
this); }
889 const std::string& requestId,
890 const std::string& message,
891 const std::string& name =
"ServiceDisabledError")
893 if (!requestId.empty())
898 const std::string& message,
899 const std::map<std::string, std::string>& debugInfo,
900 const std::map<std::string, std::string> sensitiveDebugInfo,
901 const std::string& name =
"ServiceDisabledError")
907 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<ServiceDisabledError>(*
this); }
920 static const std::string kUnrecognized =
"UNRECOGNIZED";
921 static const std::map<Extent, std::string> kExtents = {
927 return kExtents.count(extent) ? kExtents.at(extent) : kUnrecognized;
940 const std::string& message,
941 const std::string& name =
"ConsentDeniedError")
944 const std::string& message,
945 const std::map<std::string, std::string>& debugInfo,
946 const std::map<std::string, std::string> sensitiveDebugInfo,
947 const std::string& name =
"ConsentDeniedError")
949 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<ConsentDeniedError>(*
this); }
963 enum class Category {
970 const std::string& message,
971 const Category category,
972 const std::string& name =
"NoPolicyError")
975 const std::string& message,
976 const Category category,
977 const std::map<std::string, std::string>& debugInfo,
978 const std::map<std::string, std::string> sensitiveDebugInfo,
979 const std::string& name =
"NoPolicyError")
981 mCategory(category) {
982 AddDebugInfo(
"NoPolicyError.Category", GetCategoryString(category));
985 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<NoPolicyError>(*
this); }
986 Category GetCategory()
const {
return mCategory; }
988 const std::string& GetCategoryString(Category category)
const {
989 static const std::string kUnrecognized =
"UNRECOGNIZED";
990 static const std::map<Category, std::string> kCategories = {
991 { Category::SyncFile,
"SyncFile" },
992 { Category::Labels,
"Labels" },
993 { Category::Rules,
"Rules" },
995 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
1009 const std::string& message,
1010 const std::string& name =
"OperationCancelledError")
1013 const std::string& message,
1014 const std::map<std::string, std::string>& debugInfo,
1015 const std::map<std::string, std::string> sensitiveDebugInfo,
1016 const std::string& name =
"OperationCancelledError")
1018 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<OperationCancelledError>(*
this); }
1029 const std::string& message,
1030 const std::string& name =
"AdhocProtectionRequiredError")
1033 const std::string& message,
1034 const std::map<std::string, std::string>& debugInfo,
1035 const std::map<std::string, std::string> sensitiveDebugInfo,
1036 const std::string& name =
"AdhocProtectionRequiredError")
1038 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<AdhocProtectionRequiredError>(*
this); }
1049 const std::string& message,
1050 const std::string& name =
"DeprecatedApiError")
1053 const std::string& message,
1054 const std::map<std::string, std::string>& debugInfo,
1055 const std::map<std::string, std::string> sensitiveDebugInfo,
1056 const std::string& name =
"DeprecatedApiError")
1058 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<DeprecatedApiError>(*
this); }
1069 const std::string& message,
1070 const std::string& name =
"TemplateNotFoundError")
1073 const std::string& message,
1074 const std::map<std::string, std::string>& debugInfo,
1075 const std::map<std::string, std::string> sensitiveDebugInfo,
1076 const std::string& name =
"TemplateNotFoundError")
1077 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1079 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<TemplateNotFoundError>(*
this); }
1091 const std::string& message,
1092 const std::string& name =
"TemplateArchivedError")
1095 const std::string& message,
1096 const std::map<std::string, std::string>& debugInfo,
1097 const std::map<std::string, std::string> sensitiveDebugInfo,
1098 const std::string& name =
"TemplateArchivedError")
1099 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1101 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<TemplateArchivedError>(*
this); }
1113 const std::string& message,
1114 const std::string& name =
"ContentFormatNotSupportedError")
1117 const std::string& message,
1118 const std::map<std::string, std::string>& debugInfo,
1119 const std::map<std::string, std::string> sensitiveDebugInfo,
1120 const std::string& name =
"ContentFormatNotSupportedError")
1121 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1123 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<ContentFormatNotSupportedError>(*
this); }
1135 const std::string& message,
1136 const std::string& name =
"LabelNotFoundError")
1139 const std::string& message,
1140 const std::map<std::string, std::string>& debugInfo,
1141 const std::map<std::string, std::string> sensitiveDebugInfo,
1142 const std::string& name =
"LabelNotFoundError")
1143 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1145 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<LabelNotFoundError>(*
this); }
1157 const std::string& message,
1158 const std::string& name =
"LicenseNotRegisteredError")
1161 const std::string& message,
1162 const std::map<std::string, std::string>& debugInfo,
1163 const std::map<std::string, std::string> sensitiveDebugInfo,
1164 const std::string& name =
"LicenseNotRegisteredError")
1165 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1167 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<LicenseNotRegisteredError>(*
this); }
1179 const std::string& message,
1180 const std::string& name =
"LabelDisabledError")
1183 const std::string& message,
1184 const std::map<std::string, std::string>& debugInfo,
1185 const std::map<std::string, std::string> sensitiveDebugInfo,
1186 const std::string& name =
"LabelDisabledError")
1187 :
BadInputError(message, debugInfo, sensitiveDebugInfo, name) {}
1188 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<LabelDisabledError>(*
this); }
1200 const std::string& message,
1201 const std::string& name =
"CustomerKeyUnavailableError")
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 =
"CustomerKeyUnavailableError")
1209 std::shared_ptr<Error>
Clone()
const override {
return std::make_shared<CustomerKeyUnavailableError>(*
this); }
The user could not get access to the content. For example, no permissions, content revoked.
Definition error.h:652
Adhoc protection should be set to complete the action on the file.
Definition error.h:1025
An operation that required consent from user was not granted consent.
Definition error.h:936
Content Format is not supported.
Definition error.h:1109
Bring your own encryption key needed and unavailable.
Definition error.h:1196
Delegate Response Error. Thrown or returned in response to encountering an error in a delegate method...
Definition error.h:315
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:323
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:345
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:362
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:394
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:381
Caller invoked a deprecated API.
Definition error.h:1045
Base class for all errors that will be reported (thrown or returned) from MIP SDK.
Definition error.h:114
std::map< std::string, std::string > mDebugInfo
Definition error.h:225
const std::string & GetMessage(bool maskPII=false) const
Get the error message.
Definition error.h:151
void AddDebugInfo(const std::string &key, const std::string &value, bool sensitive=false)
Add debug info entry.
Definition error.h:179
const std::string & GetErrorName() const
Get the error name.
Definition error.h:144
virtual std::shared_ptr< Error > Clone() const =0
Clone the error.
char const * what() const noexcept override
Get the error message.
Definition error.h:121
std::string mMaskedMessage
Definition error.h:241
std::string CreateFormattedMessage(const std::string &message) const
Definition error.h:230
std::string mName
Definition error.h:226
virtual ErrorType GetErrorType() const
Get the error type.
Definition error.h:137
std::string mFormattedMessage
Definition error.h:240
ErrorType mType
Definition error.h:227
const std::map< std::string, std::string > & GetDebugInfo() const
Get debug info.
Definition error.h:192
std::string mMessage
Definition error.h:224
void SetMessage(const std::string &msg)
Set the error message.
Definition error.h:160
File IO error.
Definition error.h:442
Insufficient buffer error.
Definition error.h:421
Internal error. This error is thrown when something unexpected happens during execution.
Definition error.h:586
Label is disabled or inactive.
Definition error.h:1175
Label ID is not recognized.
Definition error.h:1131
License is not registered.
Definition error.h:1153
Networking error. Caused by unexpected behavior when making network calls to service endpoints.
Definition error.h:462
Category GetCategory() const
Gets the category of network failure.
Definition error.h:523
const std::string & GetCategoryString(Category category) const
Definition error.h:536
Category
Category of network error.
Definition error.h:467
Category mCategory
Definition error.h:533
int32_t mResponseStatusCode
Definition error.h:534
int32_t GetResponseStatusCode() const
Gets the HTTP response status code.
Definition error.h:530
The user could not get access to the content due to missing authentication token.
Definition error.h:853
The user could not get access to the content. For example, no permissions, content revoked.
Definition error.h:672
Category GetCategory() const
Gets the category of no permissions failure.
Definition error.h:755
std::string mOwner
Definition error.h:760
std::string GetOwner() const
Gets the owner of the document.
Definition error.h:748
std::string mReferrer
Definition error.h:759
Category
Category of no permissions error.
Definition error.h:677
@ ClientVersionNotSupported
std::string GetReferrer() const
Gets the contact in case of missing rights to the document.
Definition error.h:741
const std::string & GetCategoryString(Category category) const
Definition error.h:762
Category mCategory
Definition error.h:758
The user could not get access to the content due to extended Access checks like ABAC.
Definition error.h:782
void AddExtendedErrorInfoToDebugInfo(const std::vector< ExtendedErrorInfo > &extendedErrorInfo)
Definition error.h:813
std::vector< ExtendedErrorInfo > mExtendedErrorInfo
Definition error.h:847
Tenant policy is not configured for classification/labels.
Definition error.h:956
The operation requested by the application is not supported by the SDK.
Definition error.h:606
Operation was cancelled.
Definition error.h:1005
Current label was assigned as a privileged operation (The equivalent to an administrator operation),...
Definition error.h:632
Proxy authentication failure.
Definition error.h:559
The user could not get access to the content due to a service being disabled.
Definition error.h:874
Extent
Describes the extent for which the service is disabled.
Definition error.h:879
Extent mExtent
Definition error.h:930
const std::string & GetExtentString(Extent extent) const
Definition error.h:919
Extent GetExtent() const
Gets the extent for which the service is disabled.
Definition error.h:916
Template ID is archived and unavailable for protection.
Definition error.h:1087
Template ID is not recognized by RMS service.
Definition error.h:1065
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:106
std::map< std::string, std::string > details
Definition error.h:108
std::string message
Definition error.h:107