From d0a80d7b6209bc5a3e5145d299b8c2d6d2aa1a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 23 Mar 2021 16:56:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rpc/Client.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Rpc/Client.php b/Rpc/Client.php index 3475e2a0..60187153 100644 --- a/Rpc/Client.php +++ b/Rpc/Client.php @@ -36,22 +36,20 @@ class Client extends Component public function dispatch(string $cmd, array $param): mixed { if (empty($this->config)) { - return null; + return $this->addError('Related service not found(404)'); } if (!($this->client instanceof CClient)) { $this->client = $this->getClient(); } if (!$this->client->isConnected()) { - if (!$this->client->connect( - $this->config['host'], $this->config['port'], - $this->config['timeout'] ?? 1 - )) { - return $this->client->errCode . ':' . $this->client->errMsg; + $settings = [$this->config['host'], $this->config['port'], $this->config['timeout'] ?? 1]; + if (!$this->client->connect(...$settings)) { + return $this->addError($this->client->errMsg . '(' . $this->client->errCode . ')'); } } $isSend = $this->client->send(serialize(['cmd' => $cmd, 'body' => $param])); if ($isSend === false) { - return $this->client->errCode . ':' . $this->client->errMsg; + return $this->addError($this->client->errMsg . '(' . $this->client->errCode . ')'); } return unserialize($this->client->recv()); }