From 03f20ae4e3231c9e510c62539e17339890356e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 10 Sep 2020 15:46:20 +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 --- Database/Command.php | 9 ++++----- HttpServer/Exception/ExitException.php | 27 ++++++++++++++++++++++++++ HttpServer/Route/Router.php | 4 +++- 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 HttpServer/Exception/ExitException.php diff --git a/Database/Command.php b/Database/Command.php index c51f165a..5ed70a3e 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -199,7 +199,7 @@ class Command extends Component $this->prepare->closeCursor(); } } catch (\Throwable | Exception $exception) { - $this->error($this->sql . '. error: ' . $exception->getMessage()); + $this->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); $result = null; } finally { return $result; @@ -241,20 +241,19 @@ class Command extends Component return false; } if (($result = $this->prepare->execute($this->params)) === false) { - return $this->addError($connection->errorInfo()[2]); + return $this->addError($connection->errorInfo()[2],'mysql'); } if (!$isInsert) { return true; } $result = $connection->lastInsertId(); if ($result == 0 && $hasAutoIncrement) { - return $this->addError($connection->errorInfo()[2]); + return $this->addError($connection->errorInfo()[2],'mysql'); } return $result; } - /** * 重新构建 * @throws @@ -269,7 +268,7 @@ class Command extends Component } $this->prepare = $connect->prepare($this->sql); if (!($this->prepare instanceof PDOStatement)) { - return $this->addError($this->sql . ':' . $this->getError()); + return $this->addError($this->sql . ':' . $this->getError(),'mysql'); } return $connect; } diff --git a/HttpServer/Exception/ExitException.php b/HttpServer/Exception/ExitException.php new file mode 100644 index 00000000..a1604cd6 --- /dev/null +++ b/HttpServer/Exception/ExitException.php @@ -0,0 +1,27 @@ +method) . ' : ' . $route . '/' . $item->path; } - } return $newPath; } @@ -424,6 +424,8 @@ class Router extends Application implements RouterInterface } else { $response = send($node->dispatch(), 200); } + } catch (ExitException $exception) { + $response = send(Snowflake::app()->getLogger()->exception($exception), 200); } catch (\Throwable $exception) { $response = send(Snowflake::app()->getLogger()->exception($exception), 200); } finally {