tp6自定义异常
使用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
{
if (method_exists($e,"getStatusCode")){
$httpCode = $e->getStatusCode();
}else{
$httpCode = $this->httpCode;
}
return show(config('code.error'), $e->getMessage(),[],$httpCode);
}
}