33#ifndef API_MIP_ERROR_H_
34#define API_MIP_ERROR_H_
59 return "BadInputError";
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,
270 const std::string& message,
276 const std::string& message,
277 const std::map<std::string, std::string>& debugInfo,
278 const std::map<std::string, std::string> sensitiveDebugInfo,
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,
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,
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()) {
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.
Adhoc protection should be set to complete the action on the file.
An operation that required consent from user was not granted consent.
Content Format is not supported.
Bring your own encryption key needed and unavailable.
Delegate Response Error. Thrown or returned in response to encountering an error in a delegate method...
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...
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 ...
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 ...
DelegateResponseError(const std::string &message)
Creates an error/exception object. Call this method from a MIP delegate function to create a generic ...
DelegateResponseError(const std::string &message, long HResult)
Creates an error/exception object. Call this method from a MIP delegate function to create a generic ...
Caller invoked a deprecated API.
Base class for all errors that will be reported (thrown or returned) from MIP SDK.
std::map< std::string, std::string > mDebugInfo
const std::string & GetMessage(bool maskPII=false) const
Get the error message.
void AddDebugInfo(const std::string &key, const std::string &value, bool sensitive=false)
Add debug info entry.
const std::string & GetErrorName() const
Get the error name.
virtual std::shared_ptr< Error > Clone() const =0
Clone the error.
char const * what() const noexcept override
Get the error message.
std::string mMaskedMessage
std::string CreateFormattedMessage(const std::string &message) const
virtual ErrorType GetErrorType() const
Get the error type.
std::string mFormattedMessage
const std::map< std::string, std::string > & GetDebugInfo() const
Get debug info.
void SetMessage(const std::string &msg)
Set the error message.
Insufficient buffer error.
Internal error. This error is thrown when something unexpected happens during execution.
Label is disabled or inactive.
Label ID is not recognized.
License is not registered.
Networking error. Caused by unexpected behavior when making network calls to service endpoints.
Category GetCategory() const
Gets the category of network failure.
const std::string & GetCategoryString(Category category) const
Category
Category of network error.
int32_t mResponseStatusCode
int32_t GetResponseStatusCode() const
Gets the HTTP response status code.
The user could not get access to the content due to missing authentication token.
The user could not get access to the content. For example, no permissions, content revoked.
Category GetCategory() const
Gets the category of no permissions failure.
std::string GetOwner() const
Gets the owner of the document.
Category
Category of no permissions error.
@ ClientVersionNotSupported
std::string GetReferrer() const
Gets the contact in case of missing rights to the document.
const std::string & GetCategoryString(Category category) const
The user could not get access to the content due to extended Access checks like ABAC.
void AddExtendedErrorInfoToDebugInfo(const std::vector< ExtendedErrorInfo > &extendedErrorInfo)
std::vector< ExtendedErrorInfo > mExtendedErrorInfo
Tenant policy is not configured for classification/labels.
The operation requested by the application is not supported by the SDK.
Current label was assigned as a privileged operation (The equivalent to an administrator operation),...
Proxy authentication failure.
The user could not get access to the content due to a service being disabled.
Extent
Describes the extent for which the service is disabled.
const std::string & GetExtentString(Extent extent) const
Extent GetExtent() const
Gets the extent for which the service is disabled.
Template ID is archived and unavailable for protection.
Template ID is not recognized by RMS service.
A file Containing the common types used by the upe, file and protection modules.
@ ADHOC_PROTECTION_REQUIRED
@ CONTENT_FORMAT_NOT_SUPPORTED
@ CUSTOMER_KEY_UNAVAILABLE
@ NOT_SUPPORTED_OPERATION
@ INSUFFICIENT_BUFFER_ERROR
constexpr const char * GetErrorInfoCodesKey()
constexpr const char * GetErrorInfoDetailsKey()
constexpr const char * GetStackTraceString()
constexpr const char * GetErrorInfoMessagesKey()
constexpr const char * GetHResultString()
constexpr const char * GetBadInputErrorString()
constexpr const char * GetNoPermissionsExtendedErrorName()
std::map< std::string, std::string > details