No Description

MnsException.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace AliyunMNS\Exception;
  3. class MnsException extends \RuntimeException
  4. {
  5. private $mnsErrorCode;
  6. private $requestId;
  7. private $hostId;
  8. public function __construct($code, $message, $previousException = NULL, $mnsErrorCode = NULL, $requestId = NULL, $hostId = NULL)
  9. {
  10. parent::__construct($message, $code, $previousException);
  11. if ($mnsErrorCode == NULL)
  12. {
  13. if ($code >= 500)
  14. {
  15. $mnsErrorCode = "ServerError";
  16. }
  17. else
  18. {
  19. $mnsErrorCode = "ClientError";
  20. }
  21. }
  22. $this->mnsErrorCode = $mnsErrorCode;
  23. $this->requestId = $requestId;
  24. $this->hostId = $hostId;
  25. }
  26. public function __toString()
  27. {
  28. $str = "Code: " . $this->getCode() . " Message: " . $this->getMessage();
  29. if ($this->mnsErrorCode != NULL)
  30. {
  31. $str .= " MnsErrorCode: " . $this->mnsErrorCode;
  32. }
  33. if ($this->requestId != NULL)
  34. {
  35. $str .= " RequestId: " . $this->requestId;
  36. }
  37. if ($this->hostId != NULL)
  38. {
  39. $str .= " HostId: " . $this->hostId;
  40. }
  41. return $str;
  42. }
  43. public function getMnsErrorCode()
  44. {
  45. return $this->mnsErrorCode;
  46. }
  47. public function getRequestId()
  48. {
  49. return $this->requestId;
  50. }
  51. public function getHostId()
  52. {
  53. return $this->hostId;
  54. }
  55. }
  56. ?>