1
0

Exception.php 849 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace components;
  3. use Yii;
  4. use yii\base\UserException;
  5. /**
  6. * 异常 模型
  7. * Class Exception
  8. * @package components
  9. */
  10. class Exception extends UserException
  11. {
  12. const ERROR = 'AMQ ERROR';
  13. const UNKNOWN_ERROR_CODE = 500;
  14. /**
  15. * Exception constructor.
  16. * @param null $code
  17. * @param null $message
  18. * @param null $previous
  19. */
  20. public function __construct($code = null, $message = null, $previous = null)
  21. {
  22. if (is_numeric($message) && is_string($code)) {
  23. list($code, $message) = [$message, $code];
  24. }
  25. $code = is_numeric($code) ? $code : self::UNKNOWN_ERROR_CODE;
  26. $message = $message ?: Yii::t('error', $code);
  27. parent::__construct($message, $code, $previous);
  28. }
  29. /**
  30. * 获取异常信息
  31. * @return string
  32. */
  33. public function getName()
  34. {
  35. return self::ERROR;
  36. }
  37. }