TcpExceptionHandler.php 981 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of Hyperf.
  5. *
  6. * @link https://www.hyperf.io
  7. * @document https://hyperf.wiki
  8. * @contact group@hyperf.io
  9. * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
  10. */
  11. namespace Hyperf\JsonRpc\Exception\Handler;
  12. use Hyperf\Contract\StdoutLoggerInterface;
  13. use Hyperf\ExceptionHandler\ExceptionHandler;
  14. use Hyperf\ExceptionHandler\Formatter\FormatterInterface;
  15. use Psr\Http\Message\ResponseInterface;
  16. use Throwable;
  17. class TcpExceptionHandler extends ExceptionHandler
  18. {
  19. public function __construct(protected StdoutLoggerInterface $logger, protected FormatterInterface $formatter)
  20. {
  21. }
  22. public function handle(Throwable $throwable, ResponseInterface $response)
  23. {
  24. $this->logger->warning($this->formatter->format($throwable));
  25. $this->stopPropagation();
  26. return $response;
  27. }
  28. public function isValid(Throwable $throwable): bool
  29. {
  30. return true;
  31. }
  32. }