Http.php 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User:林志杰
  5. * Email:[email protected]
  6. * Motto:纵有疾风起,人生不言弃!
  7. * Time:2020/1/13 23:58
  8. */
  9. declare(strict_types=1);
  10. namespace app\api\exception;
  11. use think\exception\Handle;
  12. use think\Response;
  13. use Throwable;
  14. class Http extends Handle
  15. {
  16. public $httpStatus = 500;
  17. /**
  18. * Render an exception into an HTTP response.
  19. *
  20. * @access public
  21. * @param \think\Request $request
  22. * @param Throwable $e
  23. * @return Response
  24. */
  25. public function render($request, Throwable $e): Response
  26. {
  27. if (method_exists($e, "getStatusCode")) {
  28. $httpStatus = $e->getStatusCode();
  29. } else {
  30. $httpStatus = $this->httpStatus;
  31. }
  32. // 自定义异常处理机制
  33. return show(config('status.error'), $e->getMessage(), [], $httpStatus);
  34. }
  35. }