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/backup/BackupErrors.h>
9 #include <aws/backup/model/ServiceUnavailableException.h>
10 #include <aws/backup/model/ConflictException.h>
11 #include <aws/backup/model/DependencyFailureException.h>
12 #include <aws/backup/model/ResourceNotFoundException.h>
13 #include <aws/backup/model/LimitExceededException.h>
14 #include <aws/backup/model/AlreadyExistsException.h>
15 #include <aws/backup/model/InvalidResourceStateException.h>
16 #include <aws/backup/model/InvalidParameterValueException.h>
17 #include <aws/backup/model/MissingParameterValueException.h>
18 #include <aws/backup/model/InvalidRequestException.h>
19 
20 using namespace Aws::Client;
21 using namespace Aws::Utils;
22 using namespace Aws::Backup;
23 using namespace Aws::Backup::Model;
24 
25 namespace Aws
26 {
27 namespace Backup
28 {
GetModeledError()29 template<> AWS_BACKUP_API ServiceUnavailableException BackupError::GetModeledError()
30 {
31   assert(this->GetErrorType() == BackupErrors::SERVICE_UNAVAILABLE);
32   return ServiceUnavailableException(this->GetJsonPayload().View());
33 }
34 
GetModeledError()35 template<> AWS_BACKUP_API ConflictException BackupError::GetModeledError()
36 {
37   assert(this->GetErrorType() == BackupErrors::CONFLICT);
38   return ConflictException(this->GetJsonPayload().View());
39 }
40 
GetModeledError()41 template<> AWS_BACKUP_API DependencyFailureException BackupError::GetModeledError()
42 {
43   assert(this->GetErrorType() == BackupErrors::DEPENDENCY_FAILURE);
44   return DependencyFailureException(this->GetJsonPayload().View());
45 }
46 
GetModeledError()47 template<> AWS_BACKUP_API ResourceNotFoundException BackupError::GetModeledError()
48 {
49   assert(this->GetErrorType() == BackupErrors::RESOURCE_NOT_FOUND);
50   return ResourceNotFoundException(this->GetJsonPayload().View());
51 }
52 
GetModeledError()53 template<> AWS_BACKUP_API LimitExceededException BackupError::GetModeledError()
54 {
55   assert(this->GetErrorType() == BackupErrors::LIMIT_EXCEEDED);
56   return LimitExceededException(this->GetJsonPayload().View());
57 }
58 
GetModeledError()59 template<> AWS_BACKUP_API AlreadyExistsException BackupError::GetModeledError()
60 {
61   assert(this->GetErrorType() == BackupErrors::ALREADY_EXISTS);
62   return AlreadyExistsException(this->GetJsonPayload().View());
63 }
64 
GetModeledError()65 template<> AWS_BACKUP_API InvalidResourceStateException BackupError::GetModeledError()
66 {
67   assert(this->GetErrorType() == BackupErrors::INVALID_RESOURCE_STATE);
68   return InvalidResourceStateException(this->GetJsonPayload().View());
69 }
70 
GetModeledError()71 template<> AWS_BACKUP_API InvalidParameterValueException BackupError::GetModeledError()
72 {
73   assert(this->GetErrorType() == BackupErrors::INVALID_PARAMETER_VALUE);
74   return InvalidParameterValueException(this->GetJsonPayload().View());
75 }
76 
GetModeledError()77 template<> AWS_BACKUP_API MissingParameterValueException BackupError::GetModeledError()
78 {
79   assert(this->GetErrorType() == BackupErrors::MISSING_PARAMETER_VALUE);
80   return MissingParameterValueException(this->GetJsonPayload().View());
81 }
82 
GetModeledError()83 template<> AWS_BACKUP_API InvalidRequestException BackupError::GetModeledError()
84 {
85   assert(this->GetErrorType() == BackupErrors::INVALID_REQUEST);
86   return InvalidRequestException(this->GetJsonPayload().View());
87 }
88 
89 namespace BackupErrorMapper
90 {
91 
92 static const int CONFLICT_HASH = HashingUtils::HashString("ConflictException");
93 static const int DEPENDENCY_FAILURE_HASH = HashingUtils::HashString("DependencyFailureException");
94 static const int LIMIT_EXCEEDED_HASH = HashingUtils::HashString("LimitExceededException");
95 static const int ALREADY_EXISTS_HASH = HashingUtils::HashString("AlreadyExistsException");
96 static const int INVALID_RESOURCE_STATE_HASH = HashingUtils::HashString("InvalidResourceStateException");
97 static const int MISSING_PARAMETER_VALUE_HASH = HashingUtils::HashString("MissingParameterValueException");
98 static const int INVALID_REQUEST_HASH = HashingUtils::HashString("InvalidRequestException");
99 
100 
GetErrorForName(const char * errorName)101 AWSError<CoreErrors> GetErrorForName(const char* errorName)
102 {
103   int hashCode = HashingUtils::HashString(errorName);
104 
105   if (hashCode == CONFLICT_HASH)
106   {
107     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::CONFLICT), false);
108   }
109   else if (hashCode == DEPENDENCY_FAILURE_HASH)
110   {
111     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::DEPENDENCY_FAILURE), false);
112   }
113   else if (hashCode == LIMIT_EXCEEDED_HASH)
114   {
115     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::LIMIT_EXCEEDED), true);
116   }
117   else if (hashCode == ALREADY_EXISTS_HASH)
118   {
119     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::ALREADY_EXISTS), false);
120   }
121   else if (hashCode == INVALID_RESOURCE_STATE_HASH)
122   {
123     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::INVALID_RESOURCE_STATE), false);
124   }
125   else if (hashCode == MISSING_PARAMETER_VALUE_HASH)
126   {
127     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::MISSING_PARAMETER_VALUE), false);
128   }
129   else if (hashCode == INVALID_REQUEST_HASH)
130   {
131     return AWSError<CoreErrors>(static_cast<CoreErrors>(BackupErrors::INVALID_REQUEST), false);
132   }
133   return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
134 }
135 
136 } // namespace BackupErrorMapper
137 } // namespace Backup
138 } // namespace Aws
139