1/*
2* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3*
4* Licensed under the Apache License, Version 2.0 (the "License").
5* You may not use this file except in compliance with the License.
6* A copy of the License is located at
7*
8* http://aws.amazon.com/apache2.0
9*
10* or in the "license" file accompanying this file. This file is distributed
11* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12* express or implied. See the License for the specific language governing
13* permissions and limitations under the License.
14*/
15
16#include <aws/core/client/AWSError.h>
17#include <aws/core/utils/HashingUtils.h>
18#include <aws/s3/S3Errors.h>
19
20using namespace Aws::Client;
21using namespace Aws::S3;
22using namespace Aws::Utils;
23
24namespace Aws
25{
26namespace S3
27{
28namespace S3ErrorMapper
29{
30
31static const int NO_SUCH_UPLOAD_HASH = HashingUtils::HashString("NoSuchUpload");
32static const int BUCKET_ALREADY_OWNED_BY_YOU_HASH = HashingUtils::HashString("BucketAlreadyOwnedByYou");
33static const int OBJECT_ALREADY_IN_ACTIVE_TIER_HASH = HashingUtils::HashString("ObjectAlreadyInActiveTierError");
34static const int NO_SUCH_BUCKET_HASH = HashingUtils::HashString("NoSuchBucket");
35static const int NO_SUCH_KEY_HASH = HashingUtils::HashString("NoSuchKey");
36static const int OBJECT_NOT_IN_ACTIVE_TIER_HASH = HashingUtils::HashString("ObjectNotInActiveTierError");
37static const int BUCKET_ALREADY_EXISTS_HASH = HashingUtils::HashString("BucketAlreadyExists");
38
39
40AWSError<CoreErrors> GetErrorForName(const char* errorName)
41{
42 int hashCode = HashingUtils::HashString(errorName);
43
44 if (hashCode == NO_SUCH_UPLOAD_HASH)
45 {
46 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::NO_SUCH_UPLOAD), false);
47 }
48 else if (hashCode == BUCKET_ALREADY_OWNED_BY_YOU_HASH)
49 {
50 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::BUCKET_ALREADY_OWNED_BY_YOU), false);
51 }
52 else if (hashCode == OBJECT_ALREADY_IN_ACTIVE_TIER_HASH)
53 {
54 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::OBJECT_ALREADY_IN_ACTIVE_TIER), false);
55 }
56 else if (hashCode == NO_SUCH_BUCKET_HASH)
57 {
58 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::NO_SUCH_BUCKET), false);
59 }
60 else if (hashCode == NO_SUCH_KEY_HASH)
61 {
62 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::NO_SUCH_KEY), false);
63 }
64 else if (hashCode == OBJECT_NOT_IN_ACTIVE_TIER_HASH)
65 {
66 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::OBJECT_NOT_IN_ACTIVE_TIER), false);
67 }
68 else if (hashCode == BUCKET_ALREADY_EXISTS_HASH)
69 {
70 return AWSError<CoreErrors>(static_cast<CoreErrors>(S3Errors::BUCKET_ALREADY_EXISTS), false);
71 }
72 return AWSError<CoreErrors>(CoreErrors::UNKNOWN, false);
73}
74
75} // namespace S3ErrorMapper
76} // namespace S3
77} // namespace Aws
78