复制provider.php到模块下
<?php use app\ExceptionHandle; use app\Request; // 容器Provider定义文件 return [ 'think\exception\Handle' =>'app\\demo\\exception\\Http', ];
在模块下新建exception文件夹,新建http类
<?phpnamespace app\demo\exception;use think\exception\Handle;use think\Response;use Throwable;class Http extends Handle{ protected $httpStatus = 500; public function render($request, Throwable $e): Response { if( method_exists($e, "getStatusCode") ) { $httpStatus = $e->getStatusCode(); } else { $httpStatus = $this->httpStatus; } // public $httpStatus = 500; return show(config('status.error'), $e->getMessage(), [], $httpStatus); }}
来源:https://www.cnblogs.com/aln0825/p/12578816.html