Error.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #pragma once
  17. #include <string>
  18. #include <alibabacloud/oss/Export.h>
  19. #include <alibabacloud/oss/Types.h>
  20. namespace AlibabaCloud
  21. {
  22. namespace OSS
  23. {
  24. /*
  25. The status comes from the following modules: client, server, httpclient(ex. curl).
  26. server: [100-600)
  27. client: [100000-199999]
  28. curl : [200000-299999], 200000 + CURLcode
  29. it's sucessful only if the status/100 equals to 2.
  30. */
  31. const int ERROR_CLIENT_BASE = 100000;
  32. const int ERROR_CRC_INCONSISTENT = ERROR_CLIENT_BASE + 1;
  33. const int ERROR_REQUEST_DISABLE = ERROR_CLIENT_BASE + 2;
  34. const int ERROR_CURL_BASE = 200000;
  35. class ALIBABACLOUD_OSS_EXPORT Error
  36. {
  37. public:
  38. Error() = default;
  39. Error(const std::string& code, const std::string& message):
  40. status_(0),
  41. code_(code),
  42. message_(message)
  43. {
  44. }
  45. ~Error() = default;
  46. long Status() const {return status_;}
  47. const std::string& Code()const {return code_;}
  48. const std::string& Message() const {return message_;}
  49. const HeaderCollection& Headers() const { return headers_; }
  50. void setStatus(long status) { status_ = status;}
  51. void setCode(const std::string& code) { code_ = code;}
  52. void setMessage(const std::string& message) { message_ = message;}
  53. void setHeaders(const HeaderCollection& headers) { headers_ = headers; }
  54. private:
  55. long status_;
  56. std::string code_;
  57. std::string message_;
  58. HeaderCollection headers_;
  59. };
  60. }
  61. }