Improve error handling
This commit is contained in:
parent
9d3f6d9ddd
commit
1255db21ab
@ -121,6 +121,18 @@ class CommandBusClient implements CommandBusInterface
|
|||||||
$data = (array)($message->getData()['data']??[]);
|
$data = (array)($message->getData()['data']??[]);
|
||||||
$this->emit(self::EVENT_NOTIFY, [ $event, $data ]);
|
$this->emit(self::EVENT_NOTIFY, [ $event, $data ]);
|
||||||
break;
|
break;
|
||||||
|
case Message::MSGTYPE_ERROR: // error
|
||||||
|
$uuid = $message->getUuid();
|
||||||
|
$error = $message->getData()['error'];
|
||||||
|
if ($uuid === "") {
|
||||||
|
$this->emit('error', [ $error ]);
|
||||||
|
} else {
|
||||||
|
if (array_key_exists($uuid, $this->pending)) {
|
||||||
|
$this->pending[$uuid]->reject(new \Exception($error));
|
||||||
|
unset($this->pending[$uuid]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$this->connection->end('{"msg":"error","data":{"error":"Unexpected message type"}}');
|
$this->connection->end('{"msg":"error","data":{"error":"Unexpected message type"}}');
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class Message implements JsonSerializable
|
|||||||
if (!$json || empty($json['msg'])) {
|
if (!$json || empty($json['msg'])) {
|
||||||
throw new MessageException("Invalid data");
|
throw new MessageException("Invalid data");
|
||||||
}
|
}
|
||||||
return new Message($json['msg'], $json['data'], $json['uuid']);
|
return new Message($json['msg'], $json['data'], $json['uuid']??"");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asResult($result): Message
|
public function asResult($result): Message
|
||||||
|
Loading…
Reference in New Issue
Block a user