From b39e4a466b69931abad0b2f6256c02bbf8f9a125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 23 Mar 2021 11:27:33 +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 --- HttpServer/Route/Router.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 1ea9f6e4..25ad9cb5 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -75,13 +75,15 @@ class Router extends HttpService implements RouterInterface * @param $port * @param Closure|array|string $closure * @param null $method - * @throws + * @return mixed + * @throws Exception */ - public function addPortListen($port, Closure|array|string $closure, $method = null) + public function addPortListen($port, Closure|array|string $closure, $method = null): mixed { - if (!is_string($closure)) { - $this->addRoute('add-port-listen/port_' . $port, $closure, 'listen'); - } else { + try { + if (!is_string($closure)) { + return $this->addRoute('add-port-listen/port_' . $port, $closure, 'listen'); + } if (empty($method)) { throw new NotFindClassException($closure . '::' . $method); } @@ -89,7 +91,9 @@ class Router extends HttpService implements RouterInterface if (!method_exists($_closure, $method)) { throw new NotFindClassException($closure . '::' . $method); } - $this->addRoute('add-port-listen/port_' . $port, [$_closure, $method], 'listen'); + return $this->addRoute('add-port-listen/port_' . $port, [$_closure, $method], 'listen'); + } catch (\Throwable $exception) { + return $this->addError($exception); } }