改名
This commit is contained in:
@@ -419,7 +419,7 @@ class Node extends Application
|
|||||||
public function dispatch()
|
public function dispatch()
|
||||||
{
|
{
|
||||||
if (empty($this->callback)) {
|
if (empty($this->callback)) {
|
||||||
return JSON::to(404, 'Page not found.');
|
return JSON::to(404, $this->_error ?? 'Page not found.');
|
||||||
}
|
}
|
||||||
return call_user_func($this->callback, \request());
|
return call_user_func($this->callback, \request());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -417,16 +417,26 @@ class Router extends Application implements RouterInterface
|
|||||||
*/
|
*/
|
||||||
public function dispatch()
|
public function dispatch()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
/** @var Node $node */
|
/** @var Node $node */
|
||||||
$request = Context::getContext('request');
|
$request = Context::getContext('request');
|
||||||
if (!($node = $this->find_path($request))) {
|
if (!($node = $this->find_path($request))) {
|
||||||
return send(JSON::to(404, self::NOT_FOUND));
|
$response = send(JSON::to(404, self::NOT_FOUND), 404);
|
||||||
}
|
} else {
|
||||||
$response = send($node->dispatch(), 200);
|
$response = send($node->dispatch(), 200);
|
||||||
if ($node->hasAfter()) {
|
}
|
||||||
|
} 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);
|
$node->afterDispatch($response);
|
||||||
}
|
}
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user