add
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
app/exception/MyBusinessException.php
Normal file
14
app/exception/MyBusinessException.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user