..
This commit is contained in:
@@ -40,7 +40,6 @@ class DataService implements DataServiceInterface
|
|||||||
{
|
{
|
||||||
$this->campusValidator->scene('create', $data)->check();
|
$this->campusValidator->scene('create', $data)->check();
|
||||||
$campus = $this->campusModel->create($data);
|
$campus = $this->campusModel->create($data);
|
||||||
// $this->tran
|
|
||||||
return $campus->id;
|
return $campus->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,24 @@ use Hyperf\ExceptionHandler\ExceptionHandler;
|
|||||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||||
use Psr\Http\Message\MessageInterface;
|
use Psr\Http\Message\MessageInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
use function Hyperf\support\env;
|
use function Hyperf\support\env;
|
||||||
|
|
||||||
class ApiExceptionHandler extends ExceptionHandler
|
class ApiExceptionHandler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected LoggerInterface $logger;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
public function handle(Throwable $throwable, ResponseInterface $response): MessageInterface|ResponseInterface
|
public function handle(Throwable $throwable, ResponseInterface $response): MessageInterface|ResponseInterface
|
||||||
{
|
{
|
||||||
|
$this->logger->error($throwable->getMessage());
|
||||||
// 业务异常
|
// 业务异常
|
||||||
if ($throwable instanceof BusinessException) {
|
if ($throwable instanceof BusinessException) {
|
||||||
$code = $throwable->getCode();
|
$code = $throwable->getCode();
|
||||||
|
|||||||
@@ -11,10 +11,18 @@ use Hyperf\Rpc\Contract\ResponseInterface;
|
|||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Psr\Http\Message\MessageInterface;
|
use Psr\Http\Message\MessageInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class JsonRpcExceptionHandler
|
class JsonRpcExceptionHandler
|
||||||
{
|
{
|
||||||
|
protected LoggerInterface $logger;
|
||||||
|
|
||||||
|
public function __construct(LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON-RPC 异常处理.
|
* JSON-RPC 异常处理.
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
@@ -25,6 +33,8 @@ class JsonRpcExceptionHandler
|
|||||||
$responseContents = $response->getBody()->getContents();
|
$responseContents = $response->getBody()->getContents();
|
||||||
$responseContents = json_decode($responseContents, true);
|
$responseContents = json_decode($responseContents, true);
|
||||||
if (! empty($responseContents['error'])) {
|
if (! empty($responseContents['error'])) {
|
||||||
|
$this->logger->error($responseContents['error']);
|
||||||
|
|
||||||
$port = null;
|
$port = null;
|
||||||
$config = ApplicationContext::getContainer()->get(ConfigInterface::class);
|
$config = ApplicationContext::getContainer()->get(ConfigInterface::class);
|
||||||
$servers = $config->get('server.servers');
|
$servers = $config->get('server.servers');
|
||||||
|
|||||||
Reference in New Issue
Block a user