使用app目录下的provider.php
<?php use app\ExceptionHandle; return [ 'think\exception\Handle' => '\\app\\demo\\exception\\Http', ];
应用目录下新建exception 新建 HttpException.php
<?php namespace app\demo\exception; use think\exception\Handle; use think\Response; use Throwable; class Http extends Handle { public $httpCode = 500; public function render($request, Throwable $e): Response { return show(config('code.error'), $e->getMessage(),[],$this->httpCode); //return parent::render($request, $e); // TODO: Change the autogenerated stub } }