Error handling fixes

This commit is contained in:
2024-03-01 21:21:09 +01:00
parent 9bd53062b0
commit c4f3e8ae50
2 changed files with 11 additions and 12 deletions

View File

@ -73,8 +73,8 @@ class CommandBusClient implements CommandBusInterface
function (DuplexStreamInterface $connection) {
$this->connection = $connection;
$this->emit(self::EVENT_CONNECTED);
$connection->on('error', function () {
$this->emit(self::EVENT_DISCONNECTED);
$connection->on('error', function ($error) {
$this->emit(self::EVENT_DISCONNECTED, [ $error ]);
if ($this->autoReconnect) {
Loop::addTimer(1, $this->reconnect(...));
}
@ -124,15 +124,14 @@ class CommandBusClient implements CommandBusInterface
$this->emit(self::EVENT_NOTIFY, [ $event, $data ]);
break;
case Message::MSGTYPE_ERROR: // error
var_dump($message);
$uuid = $message->getUuid();
$error = $message->getData()['error'];
if ($uuid === "") {
$this->emit('error', [ $error ]);
if ($uuid && array_key_exists($uuid, $this->pending)) {
$this->pending[$uuid]->reject(new \Exception($error));
unset($this->pending[$uuid]);
} else {
if (array_key_exists($uuid, $this->pending)) {
$this->pending[$uuid]->reject(new \Exception($error));
unset($this->pending[$uuid]);
}
$this->emit('error', [ $error ]);
}
break;
default: