WapException.php 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2018/01/10
  6. */
  7. namespace app\wap\controller;
  8. use Exception;
  9. use service\JsonService;
  10. use think\exception\Handle;
  11. use think\exception\HttpException;
  12. use think\exception\ValidateException;
  13. use think\Request;
  14. use think\Url;
  15. class WapException extends Handle
  16. {
  17. public function render(Exception $e){
  18. //可以在此交由系统处理
  19. if(Request::instance()->get('_debug_info') == 'true')
  20. return parent::render($e);
  21. // 参数验证错误
  22. if ($e instanceof ValidateException) {
  23. return json($e->getError(), 422);
  24. }
  25. // 请求异常
  26. if ($e instanceof HttpException && request()->isAjax()) {
  27. return JsonService::fail('系统错误');
  28. }else{
  29. $url = 0;
  30. $title = '系统错误';
  31. $msg = addslashes($e->getMessage());
  32. exit(view('public/error',compact('title', 'msg', 'url'))->getContent());
  33. }
  34. }
  35. }