CommonException.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\exceptions;
  12. use crmeb\utils\AdminApiErrorCode;
  13. use Throwable;
  14. /**
  15. * 公共错误信息
  16. * Class CommonException
  17. * @package app\exceptions
  18. */
  19. class CommonException extends \RuntimeException
  20. {
  21. public function __construct($message, $code = 0, Throwable $previous = null)
  22. {
  23. if(is_array($message)){
  24. $errInfo = $message;
  25. $message = $errInfo[1] ?? '未知错误';
  26. if ($code === 0) {
  27. $code = $errInfo[0] ?? 400;
  28. }
  29. }
  30. // 通过错误获取code 当前方式不支持常量数组
  31. $errCode = AdminApiErrorCode::getCode($message);
  32. if ($errCode > 0) {
  33. $code = $errCode;
  34. }
  35. parent::__construct($message, $code, $previous);
  36. }
  37. }