Microsoft Information Protection SDK - C++ 1.17
API Reference Documentation for C++
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions :
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 *
26 */
33#ifndef API_MIP_ERROR_H_
34#define API_MIP_ERROR_H_
35
36#include <algorithm>
37#include <exception>
38#include <map>
39#include <memory>
40#include <sstream>
41#include <stdexcept>
42#include <string>
43#include <vector>
44
45#include "mip/common_types.h"
46#include "mip/mip_namespace.h"
47
48namespace {
49
50constexpr const char* GetStackTraceString() {
51 return "StackTrace";
52}
53
54constexpr const char* GetHResultString() {
55 return "HResult";
56}
57
58constexpr const char* GetBadInputErrorString() {
59 return "BadInputError";
60}
61
62constexpr const char* GetNoPermissionsExtendedErrorName() { return "NoPermissionsExtendedError"; }
63
64constexpr const char* GetErrorInfoCodesKey() { return "ExtendedErrorInfo_Codes"; }
65
66constexpr const char* GetErrorInfoMessagesKey() { return "ExtendedErrorInfo_Messages"; }
67
68constexpr const char* GetErrorInfoDetailsKey() { return "ExtendedErrorInfo_Details"; }
69
70} // namespace
71
72MIP_NAMESPACE_BEGIN
73
104
106 std::string code;
107 std::string message;
108 std::map<std::string, std::string> details;
109};
110
114class Error : public std::exception {
115public:
121 char const* what() const noexcept override {
122 return mFormattedMessage.c_str();
123 }
124
130 virtual std::shared_ptr<Error> Clone() const = 0;
131
137 virtual ErrorType GetErrorType() const { return mType; }
138
144 const std::string& GetErrorName() const { return mName; }
145
151 const std::string& GetMessage(bool maskPII = false) const {
152 return maskPII ? mMaskedMessage : mFormattedMessage;
153 }
154
160 void SetMessage(const std::string& msg) {
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 }
172
179 void AddDebugInfo(const std::string& key, const std::string& value, bool sensitive = false) {
180 if (!key.empty() && !value.empty()) {
181 mDebugInfo[key] = value;
182 mFormattedMessage = mFormattedMessage + ", " + key + "=" + value;
183 mMaskedMessage = mMaskedMessage + ", " + key + "=" + (sensitive ? "***" : value);
184 }
185 }
186
192 const std::map<std::string, std::string>& GetDebugInfo() const { return mDebugInfo; }
193
195 virtual ~Error() {}
196
197protected:
198 explicit Error(
199 const std::string& message,
200 const std::string& name,
201 ErrorType type)
202 : mMessage(message), mName(name), mType(type) {
205 }
206 explicit Error(
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,
211 ErrorType type)
212 : mMessage(message), mName(name), mType(type) {
215 for (const auto& entry: sensitiveDebugInfo) {
216 AddDebugInfo(entry.first, entry.second, true);
217 }
218 for (const auto& entry: debugInfo) {
219 AddDebugInfo(entry.first, entry.second);
220 }
221 }
224 std::string mMessage;
225 std::map<std::string, std::string> mDebugInfo;
226 std::string mName;
228
229private:
230 std::string CreateFormattedMessage(const std::string& message) const {
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 }
239
240 std::string mFormattedMessage;
241 std::string mMaskedMessage;
242};
243
247class BadInputError : public Error {
248public:
249
253 enum class ErrorCode {
254 General = 0,
256 ParameterParsing = 2,
258 DoubleKey = 4,
260 };
261
263 explicit BadInputError(
264 const std::string& message,
265 const std::string& name = GetBadInputErrorString(),
266 ErrorCode errorCode = ErrorCode::General)
267 : BadInputError(message, {{}}, {{}}, name, errorCode) {}
268
269 explicit BadInputError(
270 const std::string& message,
271 ErrorCode errorCode,
272 const std::string& name = GetBadInputErrorString())
273 : BadInputError(message, {{}}, {{}}, name, errorCode) {}
274
275 explicit BadInputError(
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(),
280 ErrorCode errorCode = ErrorCode::General)
281 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::BAD_INPUT_ERROR),
282 mErrorCode(errorCode) {
283 AddDebugInfo("BadInputError.Code", GetErrorCodeString(errorCode));
284 }
285 std::shared_ptr<Error> Clone() const override { return std::make_shared<BadInputError>(*this); }
294
295private:
297
298 const std::string& GetErrorCodeString(ErrorCode code) const {
299 static const std::string kUnrecognized = "UNRECOGNIZED";
300 static const std::map<ErrorCode, std::string> kCodes = {
301 { ErrorCode::General, "General" },
302 { ErrorCode::FileIsTooLargeForProtection, "FileIsTooLargeForProtection" },
303 { ErrorCode::ParameterParsing, "ParameterParsing" },
304 { ErrorCode::LicenseNotTrusted, "LicenseNotTrusted" },
305 { ErrorCode::DoubleKey, "DoubleKey" },
306 { ErrorCode::FileFormatNotSupported, "FileFormatNotSupported"},
307 };
308 return kCodes.count(code) ? kCodes.at(code) : kUnrecognized;
309 }
310};
311
316public:
323 explicit DelegateResponseError(const std::exception_ptr& except) :
324 Error(std::string(), std::string("DelegateResponseError"), ErrorType::DELEGATE_RESPONSE),
325 mCurrentException(except) {
326 if (except) {
327 try {
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());
333 }
334 }
335 }
336
346 const std::string& message,
347 const std::string& stackTrace,
348 const std::string& name = "DelegateResponseError")
349 : Error(message, name, ErrorType::DELEGATE_RESPONSE) {
350 AddDebugInfo(GetStackTraceString(), stackTrace);
351 }
352
363 const std::string& message,
364 long HResult,
365 const std::string& stackTrace,
366 const std::string& name = "DelegateResponseError")
367 : Error(message, name, ErrorType::DELEGATE_RESPONSE) {
368 std::stringstream hrStream;
369 hrStream << std::hex << HResult;
370 AddDebugInfo(GetHResultString(), hrStream.str());
371 AddDebugInfo(GetStackTraceString(), stackTrace);
372 }
373
381 DelegateResponseError(const std::string& message, long HResult)
382 : Error(message, std::string("DelegateResponseError"), ErrorType::DELEGATE_RESPONSE) {
383 std::stringstream hrStream;
384 hrStream << std::hex << HResult;
385 AddDebugInfo(GetHResultString(), hrStream.str());
386 }
387
394 DelegateResponseError(const std::string& message)
395 : Error(message, std::string("DelegateResponseError"), ErrorType::DELEGATE_RESPONSE) {
396 }
397
399 explicit DelegateResponseError(const Error& error) : Error(error) {
401 }
402
403 std::shared_ptr<Error> Clone() const override {
404 // There's nothing special about this class - a clone can simply call the copy constructor.
405 auto result = std::make_shared<mip::DelegateResponseError>(*this);
406 return std::static_pointer_cast<Error>(result);
407 }
408
409 ErrorType GetErrorType() const override { return ErrorType::DELEGATE_RESPONSE; }
410
411 const std::exception_ptr& GetExceptionPtr() const { return mCurrentException; }
412
413private:
414 std::exception_ptr mCurrentException;
416};
417
422public:
425 const std::string& message,
426 const std::string& name = "InsufficientBufferError")
427 : InsufficientBufferError(message, {{}}, {{}}, name) {}
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); }
437};
438
442class FileIOError : public Error {
443public:
445 explicit FileIOError(
446 const std::string& message,
447 const std::string& name = "FileIOError")
448 : FileIOError(message, {{}}, {{}}, name) {}
449 explicit 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")
454 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::FILE_IO_ERROR) {}
455 std::shared_ptr<Error> Clone() const override { return std::make_shared<FileIOError>(*this); }
457};
458
462class NetworkError : public Error {
463public:
467 enum class Category {
468 Unknown = 0,
470 BadResponse = 2,
472 NoConnection = 4,
473 Proxy = 5,
474 SSL = 6,
475 Timeout = 7,
476 Offline = 8,
477 Throttled = 9,
478 Cancelled = 10,
480 ServiceUnavailable = 12,
481 };
482
484 explicit NetworkError(
485 Category category,
486 const std::string& sanitizedUrl,
487 const std::string& requestId,
488 int32_t statusCode,
489 const std::string& message,
490 const std::string& name = "NetworkError")
491 : NetworkError(category, statusCode, message, {{}}, {{}}, name) {
492 if (!sanitizedUrl.empty())
493 AddDebugInfo("HttpRequest.SanitizedUrl", sanitizedUrl);
494 if (!requestId.empty())
495 AddDebugInfo("HttpRequest.Id", requestId);
496 }
497
498 explicit NetworkError(
499 Category category,
500 int32_t statusCode,
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")
505 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::NETWORK_ERROR),
506 mCategory(category),
507 mResponseStatusCode(statusCode) {
508 AddDebugInfo("NetworkError.Category", GetCategoryString(category));
509 if (statusCode != 0)
510 AddDebugInfo("HttpResponse.StatusCode", std::to_string(static_cast<int>(statusCode)));
511 }
512
513 std::shared_ptr<Error> Clone() const override {
514 return std::make_shared<NetworkError>(*this);
515 }
523 Category GetCategory() const { return mCategory; }
524
530 int32_t GetResponseStatusCode() const { return mResponseStatusCode; }
531
532private:
535
536 const std::string& GetCategoryString(Category category) const {
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 }
554};
555
560public:
563 const std::string& sanitizedUrl,
564 const std::string& requestId,
565 int32_t statusCode,
566 const std::string& message,
567 const std::string& name = "ProxyAuthenticationError")
568 : NetworkError(Category::Proxy, sanitizedUrl, requestId, statusCode, message, name) {}
570 int32_t statusCode,
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")
575 : NetworkError(Category::Proxy, statusCode, message, debugInfo, sensitiveDebugInfo, name) {}
576 std::shared_ptr<Error> Clone() const override {
577 return std::make_shared<ProxyAuthenticationError>(*this);
578 }
579 ErrorType GetErrorType() const override { return ErrorType::PROXY_AUTH_ERROR; }
581};
582
586class InternalError : public Error {
587public:
589 explicit InternalError(
590 const std::string& message,
591 const std::string& name = "InternalError")
592 : InternalError(message, {{}}, {{}}, name) {}
593 explicit 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")
598 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::INTERNAL_ERROR) {}
599 std::shared_ptr<Error> Clone() const override { return std::make_shared<InternalError>(*this); }
601};
602
606class NotSupportedError : public Error {
607public:
609 explicit NotSupportedError(
610 const std::string& message,
611 const std::string& name = "NotSupportedError")
612 : NotSupportedError(message, {{}}, {{}}, name) {}
613 explicit 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")
618 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::NOT_SUPPORTED_OPERATION) {}
619 explicit NotSupportedError(
620 const std::string& message,
621 ErrorType errorType,
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); }
626};
627
633public:
636 const std::string& message,
637 const std::string& name = "PrivilegedRequiredError")
638 : PrivilegedRequiredError(message, {{}}, {{}}, name) {}
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")
644 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::PRIVILEGED_REQUIRED) {}
645 std::shared_ptr<Error> Clone() const override { return std::make_shared<PrivilegedRequiredError>(*this); }
647};
648
652class AccessDeniedError : public Error {
653public:
655 explicit AccessDeniedError(
656 const std::string& message,
657 const std::string& name = "AccessDeniedError")
658 : AccessDeniedError(message, {{}}, {{}}, name) {}
659 explicit 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")
664 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::ACCESS_DENIED) {}
665 virtual std::shared_ptr<Error> Clone() const override { return std::make_shared<AccessDeniedError>(*this); }
667};
668
673public:
677 enum class Category {
678 Unknown = 0,
679 UserNotFound = 1,
680 AccessDenied = 2,
681 AccessExpired = 3,
682 InvalidEmail = 4,
683 UnknownTenant = 5,
684 NotOwner = 6,
687 };
688
690 explicit NoPermissionsError(
691 Category category,
692 const std::string& message,
693 const std::string& referrer = "",
694 const std::string& owner = "",
695 const std::string& name = "NoPermissionsError")
696 : NoPermissionsError(category, message, referrer, owner, {{}}, {{}}, name) {}
697 explicit NoPermissionsError(
698 Category category,
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")
705 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name), mCategory(category), mReferrer(referrer), mOwner(owner) {
706 AddDebugInfo("NoPermissionsError.Category", GetCategoryString(mCategory));
707 if (!referrer.empty())
708 AddDebugInfo("NoPermissionsError.Referrer", referrer, true);
709 if (!owner.empty())
710 AddDebugInfo("NoPermissionsError.Owner", owner, true);
711 }
712#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
713 [[deprecated]]
714#endif
715 explicit NoPermissionsError(
716 const std::string& message,
717 const std::string& referrer,
718 const std::string& owner,
719 const std::string& name = "NoPermissionsError")
720 : NoPermissionsError(Category::Unknown, message, referrer, owner, {{}}, {{}}, name) {}
721#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
722 [[deprecated]]
723#endif
724 explicit NoPermissionsError(
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")
731 : NoPermissionsError(Category::Unknown, message, referrer, owner, debugInfo, sensitiveDebugInfo, name) {}
732 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoPermissionsError>(*this); }
733 ErrorType GetErrorType() const override { return ErrorType::NO_PERMISSIONS; }
741 std::string GetReferrer() const { return mReferrer; }
742
748 std::string GetOwner() const { return mOwner; }
749
755 Category GetCategory() const { return mCategory; }
756
757private:
759 std::string mReferrer;
760 std::string mOwner;
761
762 const std::string& GetCategoryString(Category category) const {
763 static const std::string kUnrecognized = "UNRECOGNIZED";
764 static const std::map<Category, std::string> kCategories = {
765 { Category::Unknown, "Unknown" },
766 { Category::UserNotFound, "UserNotFound" },
767 { Category::AccessDenied, "AccessDenied" },
768 { Category::AccessExpired, "AccessExpired" },
769 { Category::InvalidEmail, "InvalidEmail" },
770 { Category::UnknownTenant, "UnknownTenant" },
771 { Category::NotOwner, "NotOwner" },
772 { Category::NotPremiumLicenseUser, "NotPremiumLicenseUser" },
773 { Category::ClientVersionNotSupported, "ClientVersionNotSupported" }
774 };
775 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
776 }
777};
778
783public:
785 explicit NoPermissionsExtendedError(Category category,
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())
791 : NoPermissionsError(category, message, referrer, owner, name),
792 mExtendedErrorInfo(extendedErrorInfo) { AddExtendedErrorInfoToDebugInfo(extendedErrorInfo); }
793
794 explicit NoPermissionsExtendedError(Category category,
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),
803 mExtendedErrorInfo(extendedErrorInfo) { AddExtendedErrorInfoToDebugInfo(extendedErrorInfo); }
804
805 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoPermissionsExtendedError>(*this); }
806
807 std::vector<ExtendedErrorInfo> GetExtendedErrorInfo() const {
808 return mExtendedErrorInfo;
809 }
812private:
813 void AddExtendedErrorInfoToDebugInfo(const std::vector<ExtendedErrorInfo>& extendedErrorInfo) {
814 std::stringstream codesStream;
815 std::stringstream messagesStream;
816 std::stringstream detailsStream;
817
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;
827 detailsIter++;
828 if (detailsIter != extendedErrorInfo[i].details.end()) {
829 detailsStream << mapElementSeperator;
830 }
831 }
832
833 if (i + 1 < extendedErrorInfo.size()) {
834 codesStream << objSeperator;
835 messagesStream << objSeperator;
836 detailsStream << objSeperator;
837 }
838 }
839
840 if (!extendedErrorInfo.empty()) {
841 AddDebugInfo(GetErrorInfoCodesKey(), codesStream.str());
842 AddDebugInfo(GetErrorInfoMessagesKey(), messagesStream.str());
843 AddDebugInfo(GetErrorInfoDetailsKey(), detailsStream.str());
844 }
845 }
846
847 std::vector<ExtendedErrorInfo> mExtendedErrorInfo;
848};
849
854public:
856 explicit NoAuthTokenError(
857 const std::string& message,
858 const std::string& name = "NoAuthTokenError")
859 : NoAuthTokenError(message, {{}}, {{}}, name) {}
860 explicit 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")
865 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name) {}
866 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoAuthTokenError>(*this); }
867 ErrorType GetErrorType() const override { return ErrorType::NO_AUTH_TOKEN; }
869};
870
875public:
879 enum class Extent {
880 User,
881 Device,
882 Platform,
883 Tenant,
884 };
885
887 explicit ServiceDisabledError(
888 Extent extent,
889 const std::string& requestId,
890 const std::string& message,
891 const std::string& name = "ServiceDisabledError")
892 : ServiceDisabledError(extent, message, {{}}, {{}}, name) {
893 if (!requestId.empty())
894 AddDebugInfo("HttpRequest.Id", requestId);
895 }
896 explicit ServiceDisabledError(
897 Extent extent,
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")
902 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name),
903 mExtent(extent) {
904 AddDebugInfo("ServiceDisabledError.Extent", GetExtentString(extent));
905 }
906
907 std::shared_ptr<Error> Clone() const override { return std::make_shared<ServiceDisabledError>(*this); }
908 ErrorType GetErrorType() const override { return ErrorType::DISABLED_SERVICE; }
916 Extent GetExtent() const { return mExtent; }
917
918private:
919 const std::string& GetExtentString(Extent extent) const {
920 static const std::string kUnrecognized = "UNRECOGNIZED";
921 static const std::map<Extent, std::string> kExtents = {
922 { Extent::User, "User" },
923 { Extent::Device, "Device" },
924 { Extent::Platform, "Platform" },
925 { Extent::Tenant, "Tenant" },
926 };
927 return kExtents.count(extent) ? kExtents.at(extent) : kUnrecognized;
928 }
929
931};
932
936class ConsentDeniedError : public Error {
937public:
939 explicit ConsentDeniedError(
940 const std::string& message,
941 const std::string& name = "ConsentDeniedError")
942 : ConsentDeniedError(message, {{}}, {{}}, name) {}
943 explicit 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")
948 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::CONSENT_DENIED) {}
949 std::shared_ptr<Error> Clone() const override { return std::make_shared<ConsentDeniedError>(*this); }
951};
952
956class NoPolicyError : public Error {
957public:
963 enum class Category {
964 SyncFile,
965 Labels,
966 Rules
967 };
968
969 explicit NoPolicyError(
970 const std::string& message,
971 const Category category,
972 const std::string& name = "NoPolicyError")
973 : NoPolicyError(message, category, {{}}, {{}}, name) {}
974 explicit 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")
980 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::NO_POLICY),
981 mCategory(category) {
982 AddDebugInfo("NoPolicyError.Category", GetCategoryString(category));
983 }
984
985 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoPolicyError>(*this); }
986 Category GetCategory() const { return mCategory; }
987private:
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" },
994 };
995 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
996 }
997
998 Category mCategory;
1000};
1001
1006public:
1008 explicit OperationCancelledError(
1009 const std::string& message,
1010 const std::string& name = "OperationCancelledError")
1011 : OperationCancelledError(message, {{}}, {{}}, name) {}
1012 explicit 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")
1017 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::OPERATION_CANCELLED) {}
1018 std::shared_ptr<Error> Clone() const override { return std::make_shared<OperationCancelledError>(*this); }
1020};
1021
1026public:
1029 const std::string& message,
1030 const std::string& name = "AdhocProtectionRequiredError")
1031 : AdhocProtectionRequiredError(message, {{}}, {{}}, name) {}
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")
1037 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::ADHOC_PROTECTION_REQUIRED) {}
1038 std::shared_ptr<Error> Clone() const override { return std::make_shared<AdhocProtectionRequiredError>(*this); }
1040};
1041
1046public:
1048 explicit DeprecatedApiError(
1049 const std::string& message,
1050 const std::string& name = "DeprecatedApiError")
1051 : DeprecatedApiError(message, {{}}, {{}}, name) {}
1052 explicit 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")
1057 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::DEPRECATED_API) {}
1058 std::shared_ptr<Error> Clone() const override { return std::make_shared<DeprecatedApiError>(*this); }
1060};
1061
1066public:
1068 explicit TemplateNotFoundError(
1069 const std::string& message,
1070 const std::string& name = "TemplateNotFoundError")
1071 : TemplateNotFoundError(message, {{}}, {{}}, name) {}
1072 explicit 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) {}
1078
1079 std::shared_ptr<Error> Clone() const override { return std::make_shared<TemplateNotFoundError>(*this); }
1080 ErrorType GetErrorType() const override { return ErrorType::TEMPLATE_NOT_FOUND; }
1082};
1083
1088public:
1090 explicit TemplateArchivedError(
1091 const std::string& message,
1092 const std::string& name = "TemplateArchivedError")
1093 : TemplateArchivedError(message, {{}}, {{}}, name) {}
1094 explicit 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) {}
1100
1101 std::shared_ptr<Error> Clone() const override { return std::make_shared<TemplateArchivedError>(*this); }
1102 ErrorType GetErrorType() const override { return ErrorType::TEMPLATE_ARCHIVED; }
1104};
1105
1110public:
1113 const std::string& message,
1114 const std::string& name = "ContentFormatNotSupportedError")
1115 : ContentFormatNotSupportedError(message, {{}}, {{}}, name) {}
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) {}
1122
1123 std::shared_ptr<Error> Clone() const override { return std::make_shared<ContentFormatNotSupportedError>(*this); }
1126};
1127
1132public:
1134 explicit LabelNotFoundError(
1135 const std::string& message,
1136 const std::string& name = "LabelNotFoundError")
1137 : LabelNotFoundError(message, {{}}, {{}}, name) {}
1138 explicit 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) {}
1144
1145 std::shared_ptr<Error> Clone() const override { return std::make_shared<LabelNotFoundError>(*this); }
1146 ErrorType GetErrorType() const override { return ErrorType::LABEL_NOT_FOUND; }
1148};
1149
1154public:
1157 const std::string& message,
1158 const std::string& name = "LicenseNotRegisteredError")
1159 : LicenseNotRegisteredError(message, {{}}, {{}}, name) {}
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) {}
1166
1167 std::shared_ptr<Error> Clone() const override { return std::make_shared<LicenseNotRegisteredError>(*this); }
1168 ErrorType GetErrorType() const override { return ErrorType::LICENSE_NOT_REGISTERED; }
1170};
1171
1176public:
1178 explicit LabelDisabledError(
1179 const std::string& message,
1180 const std::string& name = "LabelDisabledError")
1181 : LabelDisabledError(message, {{}}, {{}}, name) {}
1182 explicit 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); }
1189 ErrorType GetErrorType() const override { return ErrorType::LABEL_DISABLED; }
1191};
1192
1197public:
1200 const std::string& message,
1201 const std::string& name = "CustomerKeyUnavailableError")
1202 : CustomerKeyUnavailableError(message, {{}}, {{}}, name) {}
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")
1208 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name) {}
1209 std::shared_ptr<Error> Clone() const override { return std::make_shared<CustomerKeyUnavailableError>(*this); }
1212};
1213
1214MIP_NAMESPACE_END
1215
1216#endif // API_MIP_ERROR_H_
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
Bad input error, thrown when the input to an SDK API is invalid.
Definition error.h:247
ErrorCode GetErrorCode() const
Gets the errorCode of bad input.
Definition error.h:293
const std::string & GetErrorCodeString(ErrorCode code) const
Definition error.h:298
ErrorCode
ErrorCode of bad input error.
Definition error.h:253
ErrorCode mErrorCode
Definition error.h:296
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
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
@ TEMPLATE_NOT_FOUND
@ OPERATION_CANCELLED
@ PRIVILEGED_REQUIRED
@ LICENSE_NOT_REGISTERED
@ DISABLED_SERVICE
@ PROXY_AUTH_ERROR
@ CONTENT_FORMAT_NOT_SUPPORTED
@ CUSTOMER_KEY_UNAVAILABLE
@ NOT_SUPPORTED_OPERATION
@ JUSTIFICATION_REQUIRED
@ INSUFFICIENT_BUFFER_ERROR
@ DOUBLE_KEY_DISABLED
@ TEMPLATE_ARCHIVED
@ DELEGATE_RESPONSE
MIP namespace macros.
Definition error.h:105
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