Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Middleware/DtmMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use DtmClient\Exception\OngingException;
use DtmClient\Exception\RuntimeException;
use Hyperf\Contract\ConfigInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Di\Annotation\AnnotationCollector;
use Hyperf\Grpc\StatusCode;
use Hyperf\HttpMessage\Stream\SwooleStream;
Expand All @@ -33,11 +34,14 @@ class DtmMiddleware implements MiddlewareInterface

protected ConfigInterface $config;

public function __construct(Barrier $barrier, ResponseInterface $response, ConfigInterface $config)
protected StdoutLoggerInterface $logger;

public function __construct(Barrier $barrier, ResponseInterface $response, ConfigInterface $config, StdoutLoggerInterface $logger)
{
$this->barrier = $barrier;
$this->response = $response;
$this->config = $config;
$this->logger = $logger;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Expand Down Expand Up @@ -137,6 +141,7 @@ protected function handlerBarrierCall(callable $businessCall): ResponseInterface
$this->isGRPC() && $response = $response->withTrailer('grpc-status', (string) $failureException->getCode())->withTrailer('grpc-message', $failureException->getMessage());
return $response;
} catch (\Throwable $throwable) {
$this->logger->error($throwable);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里建议格式化一下成字符串,不要直接把 Throwable 这个对象直接丢到 error 里面

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PandaLIU-1111 已处理

$code = $this->isGRPC() ? 200 : Result::FAILURE_STATUS;
$response = $response->withStatus($code);
$this->isGRPC() && $response = $response->withTrailer('grpc-status', (string) Result::FAILURE_STATUS)->withTrailer('grpc-message', $throwable->getMessage());
Expand Down
1 change: 1 addition & 0 deletions src/TCC.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function callBranch($body, string $tryUrl, string $confirmUrl, string $ca
$branchRequest->branchId = $branchId;
$branchRequest->op = Operation::TRY;
$branchRequest->body = $body;
$branchRequest->branchHeaders = TransContext::getBranchHeaders();
return $this->api->transRequestBranch($branchRequest);
case Protocol::GRPC:
if (! $body instanceof Message) {
Expand Down
Loading