1 /**
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  * SPDX-License-Identifier: Apache-2.0.
4  */
5 
6 #include <aws/core/client/AWSError.h>
7 #include <aws/core/utils/HashingUtils.h>
8 #include <aws/glacier/GlacierErrors.h>
9 #include <aws/glacier/model/ServiceUnavailableException.h>
10 #include <aws/glacier/model/ResourceNotFoundException.h>
11 #include <aws/glacier/model/InsufficientCapacityException.h>
12 #include <aws/glacier/model/RequestTimeoutException.h>
13 #include <aws/glacier/model/LimitExceededException.h>
14 #include <aws/glacier/model/PolicyEnforcedException.h>
15 #include <aws/glacier/model/InvalidParameterValueException.h>
16 #include <aws/glacier/model/MissingParameterValueException.h>
17 
18 using namespace Aws::Client;
19 using namespace Aws::Utils;
20 using namespace Aws::Glacier;
21 using namespace Aws::Glacier::Model;
22 
23 namespace Aws
24 {
25 namespace Glacier
26 {
GetModeledError()27 template<> AWS_GLACIER_API ServiceUnavailableException GlacierError::GetModeledError()
28 {
29   assert(this->GetErrorType() == GlacierErrors::SERVICE_UNAVAILABLE);
30   return ServiceUnavailableException(this->GetJsonPayload().View());
31 }
32 
GetModeledError()33 template<> AWS_GLACIER_API ResourceNotFoundException GlacierError::GetModeledError()
34 {
35   assert(this->GetErrorType() == GlacierErrors::RESOURCE_NOT_FOUND);
36   return ResourceNotFoundException(this->GetJsonPayload().View());
37 }
38 
GetModeledError()39 template<> AWS_GLACIER_API InsufficientCapacityException GlacierError::GetModeledError()
40 {
41   assert(this->GetErrorType() == GlacierErrors::INSUFFICIENT_CAPACITY);
42   return InsufficientCapacityException(this->GetJsonPayload().View());
43 }
44 
GetModeledError()45 template<> AWS_GLACIER_API RequestTimeoutException GlacierError::GetModeledError()
46 {
47   assert(this->GetErrorType() == GlacierErrors::REQUEST_TIMEOUT);
48   return RequestTimeoutException(this->GetJsonPayload().View());
49 }
50 
GetModeledError()51 template<> AWS_GLACIER_API LimitExceededException GlacierError::GetModeledError()
52 {
53   assert(this->GetErrorType() == GlacierErrors::LIMIT_EXCEEDED);
54   return LimitExceededException(this->GetJsonPayload().View());
55 }
56 
GetModeledError()57 template<> AWS_GLACIER_API PolicyEnforcedException GlacierError::GetModeledError()
58 {
59   assert(this->GetErrorType() == GlacierErrors::POLICY_ENFORCED);
60   return PolicyEnforcedException(this->GetJsonPayload().View());
61 }
62 
GetModeledError()63 template<> AWS_GLACIER_API InvalidParameterValueException GlacierError::GetModeledError()
64 {
65   assert(this->GetErrorType() == GlacierErrors::INVALID_PARAMETER_VALUE);
66   return InvalidParameterValueException(this->GetJsonPayload().View());
67 }
68 
GetModeledError()69 template<> AWS_GLACIER_API MissingParameterValueException GlacierError::GetModeledError()
70 {
71   assert(this->GetErrorType() == GlacierErrors::MISSING_PARAMETER_VALUE);
72   return MissingParameterValueException(this->GetJsonPayload().View());
73 }
74 
75 namespace GlacierErrorMapper
76 {
77 
78 static const int INSUFFICIENT_CAPACITY_HASH = HashingUtils::HashString("InsufficientCapacityException");
79 static const int LIMIT_EXCEEDED_HASH = HashingUtils::HashString("LimitExceededException");
80 static const int POLICY_ENFORCED_HASH = HashingUtils::HashString("PolicyEnforcedException");
81 static const int MISSING_PARAMETER_VALUE_HASH = HashingUtils::HashString("MissingParameterValueException");
82 
83 
GetErrorForName(const char * errorName)84 AWSError<CoreErrors> GetErrorForName(const char* errorName)
85 {
86   int hashCode = HashingUtils::HashString(errorName);
87 
88   if (hashCode == INSUFFICIENT_CAPACITY_HASH)
89   {
90     return AWSError<CoreErrors>(static_cast<CoreErrors>(GlacierErrors::INSUFFICIENT_CAPACITY), false);
91   }
92   else if (hashCode == LIMIT_EXCEEDED_HASH)
93   {
94     return AWSError<CoreErrors>(static_cast<CoreErrors>(GlacierErrors::LIMIT_EXCEEDED), true);
95   }
96   else if (hashCode == POLICY_ENFORCED_HASH)
97   {
98     return AWSError<CoreErrors>(static_cast<CoreErrors>(GlacierErrors::POLICY_ENFORCED), false);
99   }
100   else if (hashCode == MISSING_PARAMETER_VALUE_HASH)
101   {
102     return AWSError<CoreErrors>(static_cast<CoreErrors>(GlacierErrors::MISSING_PARAMETER_VALUE), false);
103   }
104   return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
105 }
106 
107 } // namespace GlacierErrorMapper
108 } // namespace Glacier
109 } // namespace Aws
110