再次优化
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user