hyperf-chat/app/Exception/Handler/WebSocketExceptionHandler.php

42 lines
991 B
PHP
Raw Normal View History

2020-12-19 15:05:28 +08:00
<?php
2021-09-11 12:41:28 +08:00
declare(strict_types=1);
2020-12-19 15:05:28 +08:00
namespace App\Exception\Handler;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\ExceptionHandler\Formatter\FormatterInterface;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Psr\Http\Message\ResponseInterface;
use Throwable;
class WebSocketExceptionHandler extends ExceptionHandler
{
/**
* @var StdoutLoggerInterface
*/
protected $logger;
/**
* @var FormatterInterface
*/
protected $formatter;
public function __construct(StdoutLoggerInterface $logger, FormatterInterface $formatter)
{
2021-04-20 16:30:57 +08:00
$this->logger = $logger;
2020-12-19 15:05:28 +08:00
$this->formatter = $formatter;
}
public function handle(Throwable $throwable, ResponseInterface $response)
{
2021-05-23 17:28:04 +08:00
$stream = new SwooleStream($throwable->getMessage());
2020-12-19 15:05:28 +08:00
return $response->withBody($stream);
}
public function isValid(Throwable $throwable): bool
{
return true;
}
}