This commit is contained in:
ASUS 2025-08-13 19:09:29 +08:00
parent 275713f893
commit 75a410e376
3 changed files with 18 additions and 24 deletions

View File

@ -4,10 +4,12 @@ namespace app\common\controller;
use app\common\library\Auth; use app\common\library\Auth;
use app\common\library\token\TokenExpirationException; use app\common\library\token\TokenExpirationException;
use app\exception\MyBusinessException;
use support\exception\BusinessException;
use support\Request; use support\Request;
use HttpResponseException; use HttpResponseException;
use support\Response; use support\Response;
abstract class BaseController class BaseController
{ {
/** /**
* 无需登录的方法 * 无需登录的方法
@ -189,7 +191,7 @@ abstract class BaseController
'time' => time(), 'time' => time(),
$dataKey => $data, $dataKey => $data,
]; ];
throw new \app\exception\HttpResponseException(json($result)); throw new MyBusinessException(json_encode($result));
} }
public function ApiDataReturn($data) public function ApiDataReturn($data)

View File

@ -1,22 +0,0 @@
<?php
namespace app\exception;
use RuntimeException;
use support\Response;
class HttpResponseException extends RuntimeException
{
protected $response;
// 接收 Response 实例作为参数
public function __construct(Response $response)
{
$this->response = $response;
}
// 获取响应对象
public function getResponse()
{
return $this->response;
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace app\exception;
use support\exception\BusinessException;
use Webman\Http\Request;
use Webman\Http\Response;
class MyBusinessException extends BusinessException
{
public function render(Request $request): ?Response
{
return new Response(200, ['Content-Type' => 'application/json'], $this->getMessage());
}
}