123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * Created by PhpStorm
- * User:林志杰
- * Email:[email protected]
- * Motto:纵有疾风起,人生不言弃!
- * Time:2020/1/13 23:58
- */
- declare(strict_types=1);
- namespace app\api\exception;
- use think\exception\Handle;
- use think\Response;
- use Throwable;
- class Http extends Handle
- {
- public $httpStatus = 500;
- /**
- * Render an exception into an HTTP response.
- *
- * @access public
- * @param \think\Request $request
- * @param Throwable $e
- * @return Response
- */
- public function render($request, Throwable $e): Response
- {
- if ($e instanceof \think\Exception) {
- return show($e->getCode(), $e->getMessage());
- }
- if ($e instanceof \think\exception\HttpResponseException) {
- return parent::render($request, $e);
- }
- if (method_exists($e, "getStatusCode")) {
- $httpStatus = $e->getStatusCode();
- } else {
- $httpStatus = $this->httpStatus;
- }
- // 自定义异常处理机制
- return show(config('status.error'), $e->getMessage(), [], $httpStatus);
- }
- }
|