Http.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\common\exception;
  12. use think\exception\Handle;
  13. use think\exception\HttpException;
  14. use think\facade\Cookie;
  15. use think\facade\View;
  16. use think\Response;
  17. use Throwable;
  18. class Http extends Handle
  19. {
  20. public function render($request, Throwable $e): Response
  21. {
  22. event('write_log',$e);
  23. if($e instanceof HttpException && $e->getStatusCode() == 404){
  24. if(!$request->isAjax()) {
  25. View::engine()->layout(false);
  26. $modulename=app('http')->getName();
  27. View::assign('modulename',$modulename);
  28. View::assign('modulealis',get_module_alis($modulename));
  29. $result=View::fetch('common@/404');
  30. $response = Response::create($result, 'html', 404);
  31. return $response;
  32. }else{
  33. $response = Response::create(['code'=>0,'msg'=>'找不到页面'], 'json', 404);
  34. return $response;
  35. }
  36. }
  37. return parent::render($request, $e);
  38. }
  39. }