Microsoft Information Protection SDK - C++ 1.18
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
106
108 std::string code;
109 std::string message;
110 std::map<std::string, std::string> details;
111};
112
116class Error : public std::exception {
117public:
123 char const* what() const noexcept override {
124 return mFormattedMessage.c_str();
125 }
126
132 virtual std::shared_ptr<Error> Clone() const = 0;
133
139 virtual ErrorType GetErrorType() const { return mType; }
140
146 const std::string& GetErrorName() const { return mName; }
147
153 const std::string& GetMessage(bool maskPII = false) const {
154 return maskPII ? mMaskedMessage : mFormattedMessage;
155 }
156
162 void SetMessage(const std::string& msg) {
163 std::string* targetStrings[] = { &mFormattedMessage, &mMaskedMessage };
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);
168 } else {
169 targetString->replace(0, 0, msg);
170 }
171 }
172 mMessage = msg;
173 }
174
181 void AddDebugInfo(const std::string& key, const std::string& value, bool sensitive = false) {
182 if (!key.empty() && !value.empty()) {
183 mDebugInfo[key] = value;
184 mFormattedMessage = mFormattedMessage + ", " + key + "=" + value;
185 mMaskedMessage = mMaskedMessage + ", " + key + "=" + (sensitive ? "***" : value);
186 }
187 }
188
194 const std::map<std::string, std::string>& GetDebugInfo() const { return mDebugInfo; }
195
197 virtual ~Error() {}
198
199protected:
200 explicit Error(
201 const std::string& message,
202 const std::string& name,
203 ErrorType type)
204 : mMessage(message), mName(name), mType(type) {
207 }
208 explicit Error(
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,
213 ErrorType type)
214 : mMessage(message), mName(name), mType(type) {
217 for (const auto& entry: sensitiveDebugInfo) {
218 AddDebugInfo(entry.first, entry.second, true);
219 }
220 for (const auto& entry: debugInfo) {
221 AddDebugInfo(entry.first, entry.second);
222 }
223 }
226 std::string mMessage;
227 std::map<std::string, std::string> mDebugInfo;
228 std::string mName;
230
231private:
232 std::string CreateFormattedMessage(const std::string& message) const {
233 auto formattedMessage = message;
234
235 // Remove stray newlines
236 auto isNewlineFn = [](char c) { return c == '\n' || c == '\r'; };
237 formattedMessage.erase(std::remove_if(formattedMessage.begin(), formattedMessage.end(), isNewlineFn), formattedMessage.end());
238
239 return formattedMessage;
240 }
241
242 std::string mFormattedMessage;
243 std::string mMaskedMessage;
244};
245
249class BadInputError : public Error {
250public:
251
255 enum class ErrorCode {
256 General = 0,
258 ParameterParsing = 2,
260 DoubleKey = 4,
262 };
263
265 explicit BadInputError(
266 const std::string& message,
267 const std::string& name = GetBadInputErrorString(),
268 ErrorCode errorCode = ErrorCode::General)
269 : BadInputError(message, {{}}, {{}}, name, errorCode) {}
270
271 explicit BadInputError(
272 const std::string& message,
273 ErrorCode errorCode,
274 const std::string& name = GetBadInputErrorString())
275 : BadInputError(message, {{}}, {{}}, name, errorCode) {}
276
277 explicit BadInputError(
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(),
282 ErrorCode errorCode = ErrorCode::General)
283 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::BAD_INPUT_ERROR),
284 mErrorCode(errorCode) {
285 AddDebugInfo("BadInputError.Code", GetErrorCodeString(errorCode));
286 }
287 std::shared_ptr<Error> Clone() const override { return std::make_shared<BadInputError>(*this); }
296
297private:
299
300 const std::string& GetErrorCodeString(ErrorCode code) const {
301 static const std::string kUnrecognized = "UNRECOGNIZED";
302 static const std::map<ErrorCode, std::string> kCodes = {
303 { ErrorCode::General, "General" },
304 { ErrorCode::FileIsTooLargeForProtection, "FileIsTooLargeForProtection" },
305 { ErrorCode::ParameterParsing, "ParameterParsing" },
306 { ErrorCode::LicenseNotTrusted, "LicenseNotTrusted" },
307 { ErrorCode::DoubleKey, "DoubleKey" },
308 { ErrorCode::FileFormatNotSupported, "FileFormatNotSupported"},
309 };
310 return kCodes.count(code) ? kCodes.at(code) : kUnrecognized;
311 }
312};
313
318public:
325 explicit DelegateResponseError(const std::exception_ptr& except) :
326 Error(std::string(), std::string("DelegateResponseError"), ErrorType::DELEGATE_RESPONSE),
327 mCurrentException(except) {
328 if (except) {
329 try {
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());
335 }
336 }
337 }
338
348 const std::string& message,
349 const std::string& stackTrace,
350 const std::string& name = "DelegateResponseError")
351 : Error(message, name, ErrorType::DELEGATE_RESPONSE) {
352 AddDebugInfo(GetStackTraceString(), stackTrace);
353 }
354
365 const std::string& message,
366 long HResult,
367 const std::string& stackTrace,
368 const std::string& name = "DelegateResponseError")
369 : Error(message, name, ErrorType::DELEGATE_RESPONSE) {
370 std::stringstream hrStream;
371 hrStream << std::hex << HResult;
372 AddDebugInfo(GetHResultString(), hrStream.str());
373 AddDebugInfo(GetStackTraceString(), stackTrace);
374 }
375
383 DelegateResponseError(const std::string& message, long HResult)
384 : Error(message, std::string("DelegateResponseError"), ErrorType::DELEGATE_RESPONSE) {
385 std::stringstream hrStream;
386 hrStream << std::hex << HResult;
387 AddDebugInfo(GetHResultString(), hrStream.str());
388 }
389
396 DelegateResponseError(const std::string& message)
397 : Error(message, std::string("DelegateResponseError"), ErrorType::DELEGATE_RESPONSE) {
398 }
399
401 explicit DelegateResponseError(const Error& error) : Error(error) {
403 }
404
405 std::shared_ptr<Error> Clone() const override {
406 // There's nothing special about this class - a clone can simply call the copy constructor.
407 auto result = std::make_shared<mip::DelegateResponseError>(*this);
408 return std::static_pointer_cast<Error>(result);
409 }
410
411 ErrorType GetErrorType() const override { return ErrorType::DELEGATE_RESPONSE; }
412
413 const std::exception_ptr& GetExceptionPtr() const { return mCurrentException; }
414
415private:
416 std::exception_ptr mCurrentException;
418};
419
424public:
427 const std::string& message,
428 const std::string& name = "InsufficientBufferError")
429 : InsufficientBufferError(message, {{}}, {{}}, name) {}
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); }
439};
440
444class FileIOError : public Error {
445public:
447 explicit FileIOError(
448 const std::string& message,
449 const std::string& name = "FileIOError")
450 : FileIOError(message, {{}}, {{}}, name) {}
451 explicit 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")
456 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::FILE_IO_ERROR) {}
457 std::shared_ptr<Error> Clone() const override { return std::make_shared<FileIOError>(*this); }
459};
460
464class NetworkError : public Error {
465public:
469 enum class Category {
470 Unknown = 0,
472 BadResponse = 2,
474 NoConnection = 4,
475 Proxy = 5,
476 SSL = 6,
477 Timeout = 7,
478 Offline = 8,
479 Throttled = 9,
480 Cancelled = 10,
482 ServiceUnavailable = 12,
483 };
484
486 explicit NetworkError(
487 Category category,
488 const std::string& sanitizedUrl,
489 const std::string& requestId,
490 int32_t statusCode,
491 const std::string& message,
492 const std::string& name = "NetworkError")
493 : NetworkError(category, sanitizedUrl, requestId, statusCode, message, {{}}, {{}}, name) {}
494
495 explicit NetworkError(
496 Category category,
497 const std::string& sanitizedUrl,
498 const std::string& requestId,
499 int32_t statusCode,
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())
506 AddDebugInfo("HttpRequest.SanitizedUrl", sanitizedUrl);
507 if (!requestId.empty())
508 AddDebugInfo("HttpRequest.Id", requestId);
509 }
510
511 explicit NetworkError(
512 Category category,
513 int32_t statusCode,
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")
518 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::NETWORK_ERROR),
519 mCategory(category),
520 mResponseStatusCode(statusCode) {
521 AddDebugInfo("NetworkError.Category", GetCategoryString(category));
522 if (statusCode != 0)
523 AddDebugInfo("HttpResponse.StatusCode", std::to_string(static_cast<int>(statusCode)));
524 }
525
526 std::shared_ptr<Error> Clone() const override {
527 return std::make_shared<NetworkError>(*this);
528 }
536 Category GetCategory() const { return mCategory; }
537
543 int32_t GetResponseStatusCode() const { return mResponseStatusCode; }
544
545private:
548
549 const std::string& GetCategoryString(Category category) const {
550 static const std::string kUnrecognized = "UNRECOGNIZED";
551 static const std::map<Category, std::string> kCategories = {
552 { Category::Unknown, "Unknown" },
553 { Category::FailureResponseCode, "FailureResponseCode" },
554 { Category::BadResponse, "BadResponse" },
555 { Category::UnexpectedResponse, "UnexpectedResponse" },
556 { Category::NoConnection, "NoConnection" },
557 { Category::Proxy, "Proxy" },
558 { Category::SSL, "SSL" },
559 { Category::Timeout, "Timeout" },
560 { Category::Offline, "Offline" },
561 { Category::Throttled, "Throttled" },
562 { Category::ServiceUnavailable, "ServiceUnavailable" },
563 { Category::Cancelled, "Cancelled" },
564 };
565 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
566 }
567};
568
573public:
576 const std::string& sanitizedUrl,
577 const std::string& requestId,
578 int32_t statusCode,
579 const std::string& message,
580 const std::string& name = "ProxyAuthenticationError")
581 : NetworkError(Category::Proxy, sanitizedUrl, requestId, statusCode, message, name) {}
583 int32_t statusCode,
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")
588 : NetworkError(Category::Proxy, statusCode, message, debugInfo, sensitiveDebugInfo, name) {}
589 std::shared_ptr<Error> Clone() const override {
590 return std::make_shared<ProxyAuthenticationError>(*this);
591 }
592 ErrorType GetErrorType() const override { return ErrorType::PROXY_AUTH_ERROR; }
594};
595
599class InternalError : public Error {
600public:
602 explicit InternalError(
603 const std::string& message,
604 const std::string& name = "InternalError")
605 : InternalError(message, {{}}, {{}}, name) {}
606 explicit 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")
611 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::INTERNAL_ERROR) {}
612 std::shared_ptr<Error> Clone() const override { return std::make_shared<InternalError>(*this); }
614};
615
619class NotSupportedError : public Error {
620public:
622 explicit NotSupportedError(
623 const std::string& message,
624 const std::string& name = "NotSupportedError")
625 : NotSupportedError(message, {{}}, {{}}, name) {}
626 explicit 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")
631 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::NOT_SUPPORTED_OPERATION) {}
632 explicit NotSupportedError(
633 const std::string& message,
634 ErrorType errorType,
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); }
639};
640
646public:
649 const std::string& message,
650 const std::string& name = "PrivilegedRequiredError")
651 : PrivilegedRequiredError(message, {{}}, {{}}, name) {}
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")
657 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::PRIVILEGED_REQUIRED) {}
658 std::shared_ptr<Error> Clone() const override { return std::make_shared<PrivilegedRequiredError>(*this); }
660};
661
665class AccessDeniedError : public Error {
666public:
668 explicit AccessDeniedError(
669 const std::string& message,
670 const std::string& name = "AccessDeniedError")
671 : AccessDeniedError(message, {{}}, {{}}, name) {}
672 explicit 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")
677 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::ACCESS_DENIED) {}
678 virtual std::shared_ptr<Error> Clone() const override { return std::make_shared<AccessDeniedError>(*this); }
680};
681
686public:
690 enum class Category {
691 Unknown = 0,
692 UserNotFound = 1,
693 AccessDenied = 2,
694 AccessExpired = 3,
695 InvalidEmail = 4,
696 UnknownTenant = 5,
697 NotOwner = 6,
700 /* The following 3 error categories are related to dynamic protection. In dynamic protection, the rights for content are stored in an online location
701 where owners can have stronger ability to control access after a document has been shared */
702 FileNotFound = 9,
703 ClientUnauthorized = 10,
704 InvalidToken = 11,
705 };
706
708 explicit NoPermissionsError(
709 Category category,
710 const std::string& message,
711 const std::string& referrer = "",
712 const std::string& owner = "",
713 const std::string& name = "NoPermissionsError")
714 : NoPermissionsError(category, message, referrer, owner, {{}}, {{}}, name) {}
715 explicit NoPermissionsError(
716 Category category,
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")
723 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name), mCategory(category), mReferrer(referrer), mOwner(owner) {
724 AddDebugInfo("NoPermissionsError.Category", GetCategoryString(mCategory));
725 if (!referrer.empty())
726 AddDebugInfo("NoPermissionsError.Referrer", referrer, true);
727 if (!owner.empty())
728 AddDebugInfo("NoPermissionsError.Owner", owner, true);
729 }
730#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
731 [[deprecated]]
732#endif
733 explicit NoPermissionsError(
734 const std::string& message,
735 const std::string& referrer,
736 const std::string& owner,
737 const std::string& name = "NoPermissionsError")
738 : NoPermissionsError(Category::Unknown, message, referrer, owner, {{}}, {{}}, name) {}
739#if !defined(SWIG) && !defined(SWIG_DIRECTORS)
740 [[deprecated]]
741#endif
742 explicit NoPermissionsError(
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")
749 : NoPermissionsError(Category::Unknown, message, referrer, owner, debugInfo, sensitiveDebugInfo, name) {}
750 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoPermissionsError>(*this); }
751 ErrorType GetErrorType() const override { return ErrorType::NO_PERMISSIONS; }
759 std::string GetReferrer() const { return mReferrer; }
760
766 std::string GetOwner() const { return mOwner; }
767
773 Category GetCategory() const { return mCategory; }
774
775private:
777 std::string mReferrer;
778 std::string mOwner;
779
780 const std::string& GetCategoryString(Category category) const {
781 static const std::string kUnrecognized = "UNRECOGNIZED";
782 static const std::map<Category, std::string> kCategories = {
783 { Category::Unknown, "Unknown" },
784 { Category::UserNotFound, "UserNotFound" },
785 { Category::AccessDenied, "AccessDenied" },
786 { Category::AccessExpired, "AccessExpired" },
787 { Category::InvalidEmail, "InvalidEmail" },
788 { Category::UnknownTenant, "UnknownTenant" },
789 { Category::NotOwner, "NotOwner" },
790 { Category::NotPremiumLicenseUser, "NotPremiumLicenseUser" },
791 { Category::ClientVersionNotSupported, "ClientVersionNotSupported" },
792 { Category::FileNotFound, "FileNotFound" },
793 { Category::ClientUnauthorized, "ClientUnauthorized" },
794 { Category::InvalidToken, "InvalidToken" }
795 };
796 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
797 }
798};
799
804public:
806 explicit NoPermissionsExtendedError(Category category,
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())
812 : NoPermissionsError(category, message, referrer, owner, name),
813 mExtendedErrorInfo(extendedErrorInfo) { AddExtendedErrorInfoToDebugInfo(extendedErrorInfo); }
814
815 explicit NoPermissionsExtendedError(Category category,
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),
824 mExtendedErrorInfo(extendedErrorInfo) { AddExtendedErrorInfoToDebugInfo(extendedErrorInfo); }
825
826 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoPermissionsExtendedError>(*this); }
827
828 std::vector<ExtendedErrorInfo> GetExtendedErrorInfo() const {
829 return mExtendedErrorInfo;
830 }
833private:
834 void AddExtendedErrorInfoToDebugInfo(const std::vector<ExtendedErrorInfo>& extendedErrorInfo) {
835 std::stringstream codesStream;
836 std::stringstream messagesStream;
837 std::stringstream detailsStream;
838
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;
848 detailsIter++;
849 if (detailsIter != extendedErrorInfo[i].details.end()) {
850 detailsStream << mapElementSeperator;
851 }
852 }
853
854 if (i + 1 < extendedErrorInfo.size()) {
855 codesStream << objSeperator;
856 messagesStream << objSeperator;
857 detailsStream << objSeperator;
858 }
859 }
860
861 if (!extendedErrorInfo.empty()) {
862 AddDebugInfo(GetErrorInfoCodesKey(), codesStream.str());
863 AddDebugInfo(GetErrorInfoMessagesKey(), messagesStream.str());
864 AddDebugInfo(GetErrorInfoDetailsKey(), detailsStream.str());
865 }
866 }
867
868 std::vector<ExtendedErrorInfo> mExtendedErrorInfo;
869};
870
875public:
877 explicit NoAuthTokenError(
878 const std::string& message,
879 const std::string& name = "NoAuthTokenError")
880 : NoAuthTokenError(message, {{}}, {{}}, name) {}
881 explicit 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")
886 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name) {}
887 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoAuthTokenError>(*this); }
888 ErrorType GetErrorType() const override { return ErrorType::NO_AUTH_TOKEN; }
890};
891
896public:
900 enum class Extent {
901 User,
902 Device,
903 Platform,
904 Tenant,
905 };
906
908 explicit ServiceDisabledError(
909 Extent extent,
910 const std::string& requestId,
911 const std::string& message,
912 const std::string& name = "ServiceDisabledError")
913 : ServiceDisabledError(extent, message, {{}}, {{}}, name) {
914 if (!requestId.empty())
915 AddDebugInfo("HttpRequest.Id", requestId);
916 }
917 explicit ServiceDisabledError(
918 Extent extent,
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")
923 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name),
924 mExtent(extent) {
925 AddDebugInfo("ServiceDisabledError.Extent", GetExtentString(extent));
926 }
927
928 std::shared_ptr<Error> Clone() const override { return std::make_shared<ServiceDisabledError>(*this); }
929 ErrorType GetErrorType() const override { return ErrorType::DISABLED_SERVICE; }
937 Extent GetExtent() const { return mExtent; }
938
939private:
940 const std::string& GetExtentString(Extent extent) const {
941 static const std::string kUnrecognized = "UNRECOGNIZED";
942 static const std::map<Extent, std::string> kExtents = {
943 { Extent::User, "User" },
944 { Extent::Device, "Device" },
945 { Extent::Platform, "Platform" },
946 { Extent::Tenant, "Tenant" },
947 };
948 return kExtents.count(extent) ? kExtents.at(extent) : kUnrecognized;
949 }
950
952};
953
957class ConsentDeniedError : public Error {
958public:
960 explicit ConsentDeniedError(
961 const std::string& message,
962 const std::string& name = "ConsentDeniedError")
963 : ConsentDeniedError(message, {{}}, {{}}, name) {}
964 explicit 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")
969 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::CONSENT_DENIED) {}
970 std::shared_ptr<Error> Clone() const override { return std::make_shared<ConsentDeniedError>(*this); }
972};
973
977class NoPolicyError : public Error {
978public:
984 enum class Category {
985 SyncFile,
986 Labels,
987 Rules
988 };
989
990 explicit NoPolicyError(
991 const std::string& message,
992 const Category category,
993 const std::string& name = "NoPolicyError")
994 : NoPolicyError(message, category, {{}}, {{}}, name) {}
995 explicit 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")
1001 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::NO_POLICY),
1002 mCategory(category) {
1003 AddDebugInfo("NoPolicyError.Category", GetCategoryString(category));
1004 }
1005
1006 std::shared_ptr<Error> Clone() const override { return std::make_shared<NoPolicyError>(*this); }
1007 Category GetCategory() const { return mCategory; }
1008private:
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" },
1015 };
1016 return kCategories.count(category) ? kCategories.at(category) : kUnrecognized;
1017 }
1018
1019 Category mCategory;
1021};
1022
1027public:
1029 explicit OperationCancelledError(
1030 const std::string& message,
1031 const std::string& name = "OperationCancelledError")
1032 : OperationCancelledError(message, {{}}, {{}}, name) {}
1033 explicit 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")
1038 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::OPERATION_CANCELLED) {}
1039 std::shared_ptr<Error> Clone() const override { return std::make_shared<OperationCancelledError>(*this); }
1041};
1042
1047public:
1050 const std::string& message,
1051 const std::string& name = "AdhocProtectionRequiredError")
1052 : AdhocProtectionRequiredError(message, {{}}, {{}}, name) {}
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")
1058 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::ADHOC_PROTECTION_REQUIRED) {}
1059 std::shared_ptr<Error> Clone() const override { return std::make_shared<AdhocProtectionRequiredError>(*this); }
1061};
1062
1067public:
1069 explicit DeprecatedApiError(
1070 const std::string& message,
1071 const std::string& name = "DeprecatedApiError")
1072 : DeprecatedApiError(message, {{}}, {{}}, name) {}
1073 explicit 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")
1078 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::DEPRECATED_API) {}
1079 std::shared_ptr<Error> Clone() const override { return std::make_shared<DeprecatedApiError>(*this); }
1081};
1082
1087public:
1089 explicit TemplateNotFoundError(
1090 const std::string& message,
1091 const std::string& name = "TemplateNotFoundError")
1092 : TemplateNotFoundError(message, {{}}, {{}}, name) {}
1093 explicit 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) {}
1099
1100 std::shared_ptr<Error> Clone() const override { return std::make_shared<TemplateNotFoundError>(*this); }
1101 ErrorType GetErrorType() const override { return ErrorType::TEMPLATE_NOT_FOUND; }
1103};
1104
1109public:
1111 explicit TemplateArchivedError(
1112 const std::string& message,
1113 const std::string& name = "TemplateArchivedError")
1114 : TemplateArchivedError(message, {{}}, {{}}, name) {}
1115 explicit 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) {}
1121
1122 std::shared_ptr<Error> Clone() const override { return std::make_shared<TemplateArchivedError>(*this); }
1123 ErrorType GetErrorType() const override { return ErrorType::TEMPLATE_ARCHIVED; }
1125};
1126
1131public:
1134 const std::string& message,
1135 const std::string& name = "ContentFormatNotSupportedError")
1136 : ContentFormatNotSupportedError(message, {{}}, {{}}, name) {}
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) {}
1143
1144 std::shared_ptr<Error> Clone() const override { return std::make_shared<ContentFormatNotSupportedError>(*this); }
1147};
1148
1153public:
1155 explicit LabelNotFoundError(
1156 const std::string& message,
1157 const std::string& name = "LabelNotFoundError")
1158 : LabelNotFoundError(message, {{}}, {{}}, name) {}
1159 explicit 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) {}
1165
1166 std::shared_ptr<Error> Clone() const override { return std::make_shared<LabelNotFoundError>(*this); }
1167 ErrorType GetErrorType() const override { return ErrorType::LABEL_NOT_FOUND; }
1169};
1170
1175public:
1178 const std::string& message,
1179 const std::string& name = "LicenseNotRegisteredError")
1180 : LicenseNotRegisteredError(message, {{}}, {{}}, name) {}
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) {}
1187
1188 std::shared_ptr<Error> Clone() const override { return std::make_shared<LicenseNotRegisteredError>(*this); }
1189 ErrorType GetErrorType() const override { return ErrorType::LICENSE_NOT_REGISTERED; }
1191};
1192
1197public:
1199 explicit LabelDisabledError(
1200 const std::string& message,
1201 const std::string& name = "LabelDisabledError")
1202 : LabelDisabledError(message, {{}}, {{}}, name) {}
1203 explicit 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); }
1210 ErrorType GetErrorType() const override { return ErrorType::LABEL_DISABLED; }
1212};
1213
1218public:
1221 const std::string& message,
1222 const std::string& name = "CustomerKeyUnavailableError")
1223 : CustomerKeyUnavailableError(message, {{}}, {{}}, name) {}
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")
1229 : AccessDeniedError(message, debugInfo, sensitiveDebugInfo, name) {}
1230 std::shared_ptr<Error> Clone() const override { return std::make_shared<CustomerKeyUnavailableError>(*this); }
1233};
1234
1240public:
1242 explicit MaxDepthReachedError(
1243 const std::string& message,
1244 const std::string& name = "MaxDepthReachedError")
1245 : MaxDepthReachedError(message, {{}}, {{}}, name) {}
1246 explicit 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")
1251 : Error(message, debugInfo, sensitiveDebugInfo, name, ErrorType::MAX_DEPTH_REACHED) {}
1252 std::shared_ptr<Error> Clone() const override { return std::make_shared<MaxDepthReachedError>(*this); }
1254};
1255
1256MIP_NAMESPACE_END
1257
1258#endif // API_MIP_ERROR_H_
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
Bad input error, thrown when the input to an SDK API is invalid.
Definition error.h:249
ErrorCode GetErrorCode() const
Gets the errorCode of bad input.
Definition error.h:295
const std::string & GetErrorCodeString(ErrorCode code) const
Definition error.h:300
ErrorCode
ErrorCode of bad input error.
Definition error.h:255
ErrorCode mErrorCode
Definition error.h:298
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
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
@ TEMPLATE_NOT_FOUND
@ OPERATION_CANCELLED
@ PRIVILEGED_REQUIRED
@ LICENSE_NOT_REGISTERED
@ DISABLED_SERVICE
@ MAX_DEPTH_REACHED
@ 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:107
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