41 lines
972 B
PHP
41 lines
972 B
PHP
<?php
|
|
|
|
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)
|
|
{
|
|
$this->logger = $logger;
|
|
$this->formatter = $formatter;
|
|
}
|
|
|
|
public function handle(Throwable $throwable, ResponseInterface $response)
|
|
{
|
|
$stream = new SwooleStream((string) $throwable->getMessage());
|
|
return $response->withBody($stream);
|
|
}
|
|
|
|
public function isValid(Throwable $throwable): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|