exception.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2014 Baidu, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  4. # except in compliance with the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the
  9. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  10. # either express or implied. See the License for the specific language governing permissions
  11. # and limitations under the License.
  12. """
  13. This module defines exceptions for BCE.
  14. """
  15. from baidubce import utils
  16. from builtins import str
  17. from builtins import bytes
  18. class BceError(Exception):
  19. """Base Error of BCE."""
  20. def __init__(self, message):
  21. Exception.__init__(self, message)
  22. class BceClientError(BceError):
  23. """Error from BCE client."""
  24. def __init__(self, message):
  25. BceError.__init__(self, message)
  26. class BceServerError(BceError):
  27. """Error from BCE servers."""
  28. REQUEST_EXPIRED = b'RequestExpired'
  29. """Error threw when connect to server."""
  30. def __init__(self, message, status_code=None, code=None, request_id=None):
  31. BceError.__init__(self, message)
  32. self.status_code = status_code
  33. self.code = code
  34. self.request_id = request_id
  35. class BceHttpClientError(BceError):
  36. """Exception threw after retry"""
  37. def __init__(self, message, last_error, status_code=None, code=None, request_id=None):
  38. BceError.__init__(self, message)
  39. self.last_error = last_error
  40. self.status_code = status_code
  41. self.code = code
  42. self.request_id = request_id