AuthException.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php namespace App\Exceptions\Admin;
  2. use Exception;
  3. use Throwable;
  4. /**
  5. * 接口异常
  6. */
  7. class AuthException extends Exception
  8. {
  9. public $msg = '';
  10. public $url = '';
  11. public $wait = 3;
  12. /**
  13. * 抛出错误信息
  14. *
  15. * @param String $msg 错误提示
  16. * @param Mixed $url 跳转地址
  17. * @param Array $wait 等待时间
  18. *
  19. */
  20. public function __construct($msg='',$url='',$wait=3)
  21. {
  22. $this->msg = $msg;
  23. $this->url = $url;
  24. $this->wait = $wait;
  25. }
  26. /**
  27. * 错误提示
  28. *
  29. */
  30. public function jumpPage(){
  31. $url = $this->url;
  32. $msg = $this->msg;
  33. $wait = $this->wait;
  34. // 处理路径
  35. if ( is_null($url) ) {
  36. $url = request()->ajax() ? '' : 'javascript:history.back(-1);';
  37. } elseif ('' !== $url) {
  38. $url = (strpos($url, '://') || 0 === strpos($url, '/')) ? $url : url($url);
  39. }
  40. // 返回结果
  41. return $wait ? response(view('error',['msg'=>$msg,'url'=>$url,'wait'=>$wait])) : redirect($url,302);
  42. }
  43. }