This commit is contained in:
2020-09-09 12:01:20 +08:00
parent 30b7f7cfc9
commit a362d93b6d
2 changed files with 19 additions and 9 deletions
+18 -8
View File
@@ -417,16 +417,26 @@ class Router extends Application implements RouterInterface
*/
public function dispatch()
{
/** @var Node $node */
$request = Context::getContext('request');
if (!($node = $this->find_path($request))) {
return send(JSON::to(404, self::NOT_FOUND));
}
$response = send($node->dispatch(), 200);
if ($node->hasAfter()) {
try {
/** @var Node $node */
$request = Context::getContext('request');
if (!($node = $this->find_path($request))) {
$response = send(JSON::to(404, self::NOT_FOUND), 404);
} else {
$response = send($node->dispatch(), 200);
}
} catch (\Throwable $exception) {
$trance = JSON::to(500, $exception->getMessage(), [
'file' => $exception->getFile(),
'line' => $exception->getLine()
]);
$response = send($trance, 200);
} finally {
if (!$node->hasAfter()) {
return;
}
$node->afterDispatch($response);
}
return $response;
}