ApiStatusException.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\exceptions;
  12. /**
  13. * API应用错误信息
  14. * Class ApiException
  15. * @package crmeb\exceptions
  16. */
  17. class ApiStatusException extends \RuntimeException
  18. {
  19. protected $apiStatus;
  20. protected $apiData;
  21. public function __construct($status, $message, $data = [], $replace = [], $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. if (is_numeric($message)) {
  31. $code = $message;
  32. $message = getLang($message, $replace);
  33. }
  34. $this->apiData = $data;
  35. $this->apiStatus = $status;
  36. parent::__construct($message, $code, $previous);
  37. }
  38. /**
  39. * @return mixed
  40. */
  41. public function getApiStatus()
  42. {
  43. return $this->apiStatus;
  44. }
  45. /**
  46. * @return array|mixed
  47. */
  48. public function getApiData()
  49. {
  50. return $this->apiData;
  51. }
  52. }