Http.php 863 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zhangdadan
  5. * Date: 2017/6/6
  6. * Time: 23:09
  7. */
  8. namespace app\core\exception;
  9. use Exception;
  10. use think\exception\Handle;
  11. use think\exception\HttpException;
  12. use think\Response;
  13. use tool\Common;
  14. class Http extends Handle
  15. {
  16. public function render(Exception $e)
  17. {
  18. if ($e instanceof HttpException) {
  19. $statusCode = $e->getStatusCode();
  20. Response::create(Common::rj($statusCode, $e->getMessage()), 'json')->code($statusCode)->send();
  21. }
  22. else if ($e instanceof AppException) {
  23. $statusCode = $e->getStatusCode();
  24. Response::create(Common::rj($e->getCode(), $e->getMessage()), 'json')->code($statusCode)->send();
  25. }
  26. //TODO::开发者对异常的操作
  27. //可以在此交由系统处理
  28. return parent::render($e);
  29. }
  30. }