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/storagegateway/StorageGatewayErrors.h>
9 #include <aws/storagegateway/model/ServiceUnavailableError.h>
10 #include <aws/storagegateway/model/InternalServerError.h>
11 #include <aws/storagegateway/model/InvalidGatewayRequestException.h>
12 
13 using namespace Aws::Client;
14 using namespace Aws::Utils;
15 using namespace Aws::StorageGateway;
16 using namespace Aws::StorageGateway::Model;
17 
18 namespace Aws
19 {
20 namespace StorageGateway
21 {
GetModeledError()22 template<> AWS_STORAGEGATEWAY_API ServiceUnavailableError StorageGatewayError::GetModeledError()
23 {
24   assert(this->GetErrorType() == StorageGatewayErrors::SERVICE_UNAVAILABLE);
25   return ServiceUnavailableError(this->GetJsonPayload().View());
26 }
27 
GetModeledError()28 template<> AWS_STORAGEGATEWAY_API InternalServerError StorageGatewayError::GetModeledError()
29 {
30   assert(this->GetErrorType() == StorageGatewayErrors::INTERNAL_FAILURE);
31   return InternalServerError(this->GetJsonPayload().View());
32 }
33 
GetModeledError()34 template<> AWS_STORAGEGATEWAY_API InvalidGatewayRequestException StorageGatewayError::GetModeledError()
35 {
36   assert(this->GetErrorType() == StorageGatewayErrors::INVALID_GATEWAY_REQUEST);
37   return InvalidGatewayRequestException(this->GetJsonPayload().View());
38 }
39 
40 namespace StorageGatewayErrorMapper
41 {
42 
43 static const int INVALID_GATEWAY_REQUEST_HASH = HashingUtils::HashString("InvalidGatewayRequestException");
44 
45 
GetErrorForName(const char * errorName)46 AWSError<CoreErrors> GetErrorForName(const char* errorName)
47 {
48   int hashCode = HashingUtils::HashString(errorName);
49 
50   if (hashCode == INVALID_GATEWAY_REQUEST_HASH)
51   {
52     return AWSError<CoreErrors>(static_cast<CoreErrors>(StorageGatewayErrors::INVALID_GATEWAY_REQUEST), false);
53   }
54   return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
55 }
56 
57 } // namespace StorageGatewayErrorMapper
58 } // namespace StorageGateway
59 } // namespace Aws
60