1 /*
2  * Copyright 2009-2017 Alibaba Cloud 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  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 #include <string>
19 #include <alibabacloud/oss/Export.h>
20 #include <alibabacloud/oss/Types.h>
21 
22 namespace AlibabaCloud
23 {
24 namespace OSS
25 {
26     /*
27     The status comes from the following modules: client, server, httpclient(ex. curl).
28     server: [100-600)
29     client: [100000-199999]
30     curl  : [200000-299999], 200000 + CURLcode
31 
32     it's sucessful only if the status/100 equals to 2.
33     */
34     const int ERROR_CLIENT_BASE      = 100000;
35     const int ERROR_CRC_INCONSISTENT = ERROR_CLIENT_BASE + 1;
36     const int ERROR_REQUEST_DISABLE  = ERROR_CLIENT_BASE + 2;
37 
38     const int ERROR_CURL_BASE = 200000;
39 
40     class ALIBABACLOUD_OSS_EXPORT Error
41     {
42     public:
43         Error() = default;
Error(const std::string & code,const std::string & message)44         Error(const std::string& code, const std::string& message):
45             status_(0),
46             code_(code),
47             message_(message)
48         {
49         }
50         ~Error() = default;
51 
Status()52         long Status() const {return status_;}
Code()53         const std::string& Code()const {return code_;}
Message()54         const std::string& Message() const {return message_;}
Headers()55         const HeaderCollection& Headers() const { return headers_; }
setStatus(long status)56         void setStatus(long status) { status_ = status;}
setCode(const std::string & code)57         void setCode(const std::string& code) { code_ = code;}
setMessage(const std::string & message)58         void setMessage(const std::string& message) { message_ = message;}
setHeaders(const HeaderCollection & headers)59         void setHeaders(const HeaderCollection& headers) { headers_ = headers; }
60     private:
61         long status_;
62         std::string code_;
63         std::string message_;
64         HeaderCollection headers_;
65     };
66 }
67 }
68