使用app目录下的provider.php
<?php use appExceptionHandle; return [ 'thinkexceptionHandle' => '\app\demo\exception\Http', ];
应用目录下新建exception 新建 HttpException.php
<?php
namespace appdemoexception;
use thinkexceptionHandle;
use thinkResponse;
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);
}
}