This commit is contained in:
2021-03-23 18:23:45 +08:00
parent 4e1020e05a
commit c3a89d4ddd
2 changed files with 8 additions and 7 deletions
+1 -4
View File
@@ -53,10 +53,7 @@ class Client extends Component
return $this->addError($this->client->errMsg . '(' . $this->client->errCode . ')');
}
$response = $this->client->recv();
$this->client->close();
if (is_bool($unpack = Json::decode($response))) {
if (is_bool($unpack = Json::decode($this->client->recv()))) {
return $this->addError('Service return data format error(500)');
}
return $unpack;
+7 -3
View File
@@ -70,10 +70,14 @@ class Service extends Component
try {
/** @var Request $request */
$request = Context::getContext('request');
if (($node = router()->find_path($this->replace($request, $service))) === null) {
if (($node = router()->find_path(Service::replace($request, $service))) === null) {
throw new Exception('Cmd not find.');
}
return Json::encode($node->dispatch());
$response = $node->dispatch();
if (is_string($response)) {
return $response;
}
return Json::encode($response);
} catch (\Throwable $exception) {
$this->addError($exception);
return Json::encode(['state' => 'fail', 'message' => $exception->getMessage()]);
@@ -88,7 +92,7 @@ class Service extends Component
* @return Request
* @throws Exception
*/
public function replace(Request $request, array $service): Request
public static function replace(Request $request, array $service): Request
{
$body = $request->params->getBodyAndClear();
if (is_null($serialize = unserialize($body))) {