diff --git a/wechaty-puppet-service/IO/Github/Wechaty/PuppetService/PuppetService.php b/wechaty-puppet-service/IO/Github/Wechaty/PuppetService/PuppetService.php index d5ede12..5039430 100644 --- a/wechaty-puppet-service/IO/Github/Wechaty/PuppetService/PuppetService.php +++ b/wechaty-puppet-service/IO/Github/Wechaty/PuppetService/PuppetService.php @@ -26,6 +26,7 @@ use IO\Github\Wechaty\PuppetService\Exceptions\PuppetServiceException; use IO\Github\Wechaty\Util\Console; use IO\Github\Wechaty\Util\Logger; +use LM\Exception; use Wechaty\Puppet\ContactPayloadResponse; use Wechaty\Puppet\EventResponse; use Wechaty\Puppet\EventType; @@ -797,18 +798,23 @@ function ($metadata, // WECHATY_PUPPET_SERVICE_TLS_CA_CERT // WECHATY_PUPPET_SERVICE_TLS_SERVER_NAME $noTls = getenv("WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_CLIENT"); - if($noTls === "true" || $noTls === true) { - Logger::DEBUG("start client with no tls"); - $this->_grpcClient = new \Wechaty\PuppetClient($hostname, [ - 'credentials' => \Grpc\ChannelCredentials::createInsecure(), - 'update_metadata' => $updateMetadata, - ]); - } else { - Logger::DEBUG("start client with tls"); - $this->_grpcClient = new \Wechaty\PuppetClient($hostname, [ - 'credentials' => \Grpc\ChannelCredentials::createSsl(WechatyCA::TLS_CA_CERT), - 'update_metadata' => $updateMetadata, - ]); + try { + if($noTls === "true" || $noTls === true) { + Logger::DEBUG("start client with no tls"); + $this->_grpcClient = new \Wechaty\PuppetClient($hostname, [ + 'credentials' => \Grpc\ChannelCredentials::createInsecure(), + 'update_metadata' => $updateMetadata, + ]); + } else { + Logger::DEBUG("start client with tls"); + $this->_grpcClient = new \Wechaty\PuppetClient($hostname, [ + 'credentials' => \Grpc\ChannelCredentials::createSsl(WechatyCA::TLS_CA_CERT), + 'update_metadata' => $updateMetadata, + ]); + } + } catch (\Exception $e) { + Logger::ERR("start client error"); + Logger::ERR($e); } return $this->_grpcClient;