Http.php 749 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 97
  5. */
  6. namespace app\demo\exception;
  7. use think\exception\Handle;
  8. use think\Response;
  9. use Throwable;
  10. class Http extends Handle{
  11. public $httpStatus = 500;
  12. /**
  13. * Render an exception into an HTTP response.
  14. *
  15. * @access public
  16. * @param \think\Request $request
  17. * @param Throwable $e
  18. * @return Response
  19. */
  20. public function render($request, Throwable $e): Response
  21. {
  22. if(method_exists($e,"getStatusCode")){
  23. $httpStatus = $e->getStatusCode();
  24. }else{
  25. $httpStatus = $this->httpStatus;
  26. }
  27. // 添加自定义异常处理机制
  28. return show(config("status.error"),$e->getMessage(),[],$httpStatus);
  29. }
  30. }