exceptions.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. #
  12. #
  13. # Unless required by applicable law or agreed to in writing,
  14. # software distributed under the License is distributed on an
  15. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. # KIND, either express or implied. See the License for the
  17. # specific language governing permissions and limitations
  18. # under the License.
  19. # coding=utf-8
  20. """
  21. SDK exception module.
  22. """
  23. from aliyunsdkcore.acs_exception import error_type
  24. class ClientException(Exception):
  25. """client exception"""
  26. def __init__(self, code, msg):
  27. """
  28. :param code: error code
  29. :param message: error message
  30. :return:
  31. """
  32. Exception.__init__(self)
  33. self.__error_type = error_type.ERROR_TYPE_CLIENT
  34. self.message = msg
  35. self.error_code = code
  36. def __str__(self):
  37. return "%s %s" % (
  38. self.error_code,
  39. self.message,
  40. )
  41. def set_error_code(self, code):
  42. self.error_code = code
  43. def set_error_msg(self, msg):
  44. self.message = msg
  45. def get_error_type(self):
  46. return self.__error_type
  47. def get_error_code(self):
  48. return self.error_code
  49. def get_error_msg(self):
  50. return self.message
  51. class ServerException(Exception):
  52. """
  53. server exception
  54. """
  55. def __init__(self, code, msg, http_status=None, request_id=None):
  56. Exception.__init__(self)
  57. self.error_code = code
  58. self.message = msg
  59. self.__error_type = error_type.ERROR_TYPE_SERVER
  60. self.http_status = http_status
  61. self.request_id = request_id
  62. def __str__(self):
  63. return "HTTP Status: %s Error:%s %s RequestID: %s" % (
  64. str(self.http_status),
  65. self.error_code,
  66. self.message,
  67. self.request_id
  68. )
  69. def set_error_code(self, code):
  70. self.error_code = code
  71. def set_error_msg(self, msg):
  72. self.message = msg
  73. def get_error_type(self):
  74. return self.__error_type
  75. def get_error_code(self):
  76. return self.error_code
  77. def get_error_msg(self):
  78. return self.message
  79. def get_http_status(self):
  80. return self.http_status
  81. def get_request_id(self):
  82. return self.request_id