OssException.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace OSS\Core;
  3. /**
  4. * Class OssException
  5. *
  6. * This is the class that OSSClient is expected to thrown, which the caller needs to handle properly.
  7. * It has the OSS specific errors which is useful for troubleshooting.
  8. *
  9. * @package OSS\Core
  10. */
  11. class OssException extends \Exception
  12. {
  13. private $details = array();
  14. function __construct($details)
  15. {
  16. if (is_array($details)) {
  17. $message = $details['code'] . ': ' . $details['message']
  18. . ' RequestId: ' . $details['request-id'];
  19. parent::__construct($message);
  20. $this->details = $details;
  21. } else {
  22. $message = $details;
  23. parent::__construct($message);
  24. }
  25. }
  26. public function getHTTPStatus()
  27. {
  28. return isset($this->details['status']) ? $this->details['status'] : '';
  29. }
  30. public function getRequestId()
  31. {
  32. return isset($this->details['request-id']) ? $this->details['request-id'] : '';
  33. }
  34. public function getErrorCode()
  35. {
  36. return isset($this->details['code']) ? $this->details['code'] : '';
  37. }
  38. public function getErrorMessage()
  39. {
  40. return isset($this->details['message']) ? $this->details['message'] : '';
  41. }
  42. public function getDetails()
  43. {
  44. return isset($this->details['body']) ? $this->details['body'] : '';
  45. }
  46. }