TeaError.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace AlibabaCloud\Tea\Exception;
  3. use RuntimeException;
  4. /**
  5. * Class TeaError.
  6. */
  7. class TeaError extends RuntimeException
  8. {
  9. public $message = '';
  10. public $code = 0;
  11. public $data;
  12. public $name = '';
  13. private $errorInfo;
  14. /**
  15. * TeaError constructor.
  16. *
  17. * @param array $errorInfo
  18. * @param string $message
  19. * @param int $code
  20. * @param null|\Throwable $previous
  21. */
  22. public function __construct($errorInfo = [], $message = '', $code = 0, $previous = null)
  23. {
  24. parent::__construct((string) $message, (int) $code, $previous);
  25. $this->errorInfo = $errorInfo;
  26. if (!empty($errorInfo)) {
  27. $properties = ['name', 'message', 'code', 'data'];
  28. foreach ($properties as $property) {
  29. if (isset($errorInfo[$property])) {
  30. $this->{$property} = $errorInfo[$property];
  31. }
  32. }
  33. }
  34. }
  35. /**
  36. * @return array
  37. */
  38. public function getErrorInfo()
  39. {
  40. return $this->errorInfo;
  41. }
  42. }