This commit is contained in:
2020-12-16 17:48:01 +08:00
parent f36f9e72ea
commit f4893843cd
2 changed files with 12 additions and 13 deletions
+3
View File
@@ -6,6 +6,7 @@ namespace HttpServer\Events;
use Exception; use Exception;
use HttpServer\Abstracts\Callback; use HttpServer\Abstracts\Callback;
use HttpServer\Exception\ExitException;
use HttpServer\Http\Context; use HttpServer\Http\Context;
use HttpServer\Http\Request as HRequest; use HttpServer\Http\Request as HRequest;
use HttpServer\Http\Response as HResponse; use HttpServer\Http\Response as HResponse;
@@ -60,6 +61,8 @@ class OnRequest extends Callback
return $sResponse->send($sRequest->isNotFound(), 200); return $sResponse->send($sRequest->isNotFound(), 200);
} }
return Snowflake::app()->getRouter()->dispatch(); return Snowflake::app()->getRouter()->dispatch();
} catch (ExitException $exception) {
return send($exception->getMessage(), $exception->getCode());
} catch (Error | \Throwable $exception) { } catch (Error | \Throwable $exception) {
return $this->sendErrorMessage($exception); return $this->sendErrorMessage($exception);
} finally { } finally {
+7 -11
View File
@@ -471,23 +471,19 @@ class Router extends Application implements RouterInterface
/** /**
* @return mixed|void * @return mixed
* @throws * @throws
*/ */
public function dispatch() public function dispatch(): mixed
{ {
try {
if (!($node = $this->find_path(\request()))) { if (!($node = $this->find_path(\request()))) {
return send(self::NOT_FOUND, 404); return send(self::NOT_FOUND, 404);
} else {
send($response = $node->dispatch(), 200);
if (!$node->hasAfter()) {
return null;
} }
send($node->dispatch(), 200); return $node->afterDispatch($response);
if ($node->hasAfter()) {
$node->afterDispatch(\request());
}
} catch (ExitException $exception) {
send($exception->getMessage(), $exception->getCode());
} catch (\Throwable $exception) {
send($this->exception($exception), 200);
} }
} }