再次优化

This commit is contained in:
阿不叮咚
2025-09-24 15:51:38 +08:00
parent edd4effc95
commit 998f8d8356
3 changed files with 15 additions and 10 deletions

View File

@@ -4,14 +4,21 @@ declare(strict_types=1);
namespace Aether;
use Hyperf\Context\ApplicationContext;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\Rpc\Protocol;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Throwable;
use Hyperf\Context\Context;
class RpcExceptionHandler extends ExceptionHandler
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
{
// 微服务间调用返回更精简的错误信息
@@ -21,7 +28,8 @@ class RpcExceptionHandler extends ExceptionHandler
'request_id' => Context::get('request_id', ''),
];
$protocol = make(Protocol::class);
$protocol = ApplicationContext::getContainer()->get(Protocol::class);
// $response->getBody()->write($protocol->pack($data));
$response->getBody()->write($protocol->pack($data));
return $response;