WapException.php 1.5 KB

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