WapException.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 basic;
  12. use Exception;
  13. use service\JsonService;
  14. use think\Config;
  15. use think\exception\Handle;
  16. use think\exception\HttpException;
  17. use think\exception\ValidateException;
  18. use think\Request;
  19. use think\Url;
  20. class WapException extends Handle
  21. {
  22. public function render(Exception $e)
  23. {
  24. //可以在此交由系统处理
  25. if(Config::get('app_debug')) return parent::render($e);
  26. // 参数验证错误
  27. if ($e instanceof ValidateException) {
  28. return json($e->getError(), 422);
  29. }
  30. // 请求异常
  31. if ($e instanceof HttpException && request()->isAjax()) {
  32. return JsonService::fail('系统错误');
  33. }else{
  34. $url = 0;
  35. $title = '系统错误';
  36. $msg = addslashes($e->getMessage());
  37. exit(view('public/error',compact('title', 'msg', 'url'))->getContent());
  38. }
  39. }
  40. }