复制provider.php到模块下
<?php use appExceptionHandle; use appRequest; // 容器Provider定义文件 return [ 'thinkexceptionHandle' =>'app\demo\exception\Http', ];
在模块下新建exception文件夹,新建http类
<?php
namespace appdemoexception;
use thinkexceptionHandle;
use thinkResponse;
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);
}
}