1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 6 #pragma once 7 8 #include <aws/core/Core_EXPORTS.h> 9 #include <aws/core/utils/memory/stl/AWSString.h> 10 11 namespace Aws 12 { 13 namespace Http 14 { 15 class HttpResponse; 16 enum class HttpResponseCode; 17 } 18 19 namespace Utils 20 { 21 namespace Xml 22 { 23 class XmlDocument; 24 } 25 namespace Json 26 { 27 class JsonValue; 28 } 29 } 30 31 namespace Client 32 { 33 enum class CoreErrors; 34 35 template<typename ERROR_TYPE> 36 class AWSError; 37 38 /** 39 * Marshaller for core error types. 40 */ 41 class AWS_CORE_API AWSErrorMarshaller 42 { 43 public: ~AWSErrorMarshaller()44 virtual ~AWSErrorMarshaller() {} 45 46 /** 47 * Converts an exceptionName and message into an Error object, if it can be parsed. Otherwise, it returns 48 * and AWSError with CoreErrors::UNKNOWN as the error type. 49 */ 50 virtual AWSError<CoreErrors> Marshall(const Aws::Http::HttpResponse& response) const = 0; 51 /** 52 * Attempts to finds an error code by the exception name. Otherwise returns CoreErrors::UNKNOWN as the error type. 53 */ 54 virtual AWSError<CoreErrors> FindErrorByName(const char* exceptionName) const; 55 virtual AWSError<CoreErrors> FindErrorByHttpResponseCode(Aws::Http::HttpResponseCode code) const; 56 /** 57 * Attempts to extract region from error. 58 */ ExtractRegion(const AWSError<CoreErrors> &)59 virtual Aws::String ExtractRegion(const AWSError<CoreErrors>&) const { return {}; } 60 /** 61 * Attempts to extract endpoint from error. 62 */ ExtractEndpoint(const AWSError<CoreErrors> &)63 virtual Aws::String ExtractEndpoint(const AWSError<CoreErrors>&) const { return {}; } 64 protected: 65 AWSError<CoreErrors> Marshall(const Aws::String& exceptionName, const Aws::String& message) const; 66 }; 67 68 class AWS_CORE_API JsonErrorMarshaller : public AWSErrorMarshaller 69 { 70 using AWSErrorMarshaller::Marshall; 71 public: 72 /** 73 * Converts an exceptionName and message into an Error object, if it can be parsed. Otherwise, it returns 74 * and AWSError with CoreErrors::UNKNOWN as the error type. 75 */ 76 AWSError<CoreErrors> Marshall(const Aws::Http::HttpResponse& response) const override; 77 78 protected: 79 const Aws::Utils::Json::JsonValue& GetJsonPayloadFromError(const AWSError<CoreErrors>&) const; 80 }; 81 82 class AWS_CORE_API XmlErrorMarshaller : public AWSErrorMarshaller 83 { 84 using AWSErrorMarshaller::Marshall; 85 public: 86 /** 87 * Converts an exceptionName and message into an Error object, if it can be parsed. Otherwise, it returns 88 * and AWSError with CoreErrors::UNKNOWN as the error type. 89 */ 90 AWSError<CoreErrors> Marshall(const Aws::Http::HttpResponse& response) const override; 91 92 protected: 93 const Aws::Utils::Xml::XmlDocument& GetXmlPayloadFromError(const AWSError<CoreErrors>&) const; 94 }; 95 96 } // namespace Client 97 } // namespace Aws 98