This commit is contained in:
as2252258@163.com
2021-04-21 01:52:11 +08:00
parent 69908bcf72
commit 8e35c0e6d2
+16 -16
View File
@@ -515,11 +515,19 @@ class Node extends HttpService
*/ */
public function dispatch(): mixed public function dispatch(): mixed
{ {
Context::setContext('dispatch-param', func_get_args()); try {
if (empty($this->callback)) { Context::setContext('dispatch-param', func_get_args());
return Json::to(404, $this->errorMsg()); if (empty($this->callback)) {
return Json::to(404, $this->errorMsg());
}
return $this->httpFilter();
} catch (Throwable $throwable) {
$this->addError($throwable, 'throwable');
$code = $throwable->getCode() == 0 ? 500 : $throwable->getCode();
return Json::to($code, $throwable->getMessage());
} }
return $this->httpFilter();
} }
@@ -529,18 +537,10 @@ class Node extends HttpService
*/ */
private function httpFilter(): mixed private function httpFilter(): mixed
{ {
try { if ($this->handler instanceof Closure) {
if ($this->handler instanceof Closure) { return call_user_func($this->handler, \request());
return call_user_func($this->handler, \request()); } else {
} else { return $this->runValidator([\request()]);
return $this->runValidator([\request()]);
}
} catch (Throwable $throwable) {
$this->addError($throwable, 'throwable');
$code = $throwable->getCode() == 0 ? 500 : $throwable->getCode();
return Json::to($code, $throwable->getMessage());
} }
} }