This commit is contained in:
as2252258@163.com
2021-04-21 01:52:11 +08:00
parent 69908bcf72
commit 8e35c0e6d2
+8 -8
View File
@@ -515,11 +515,19 @@ class Node extends HttpService
*/ */
public function dispatch(): mixed public function dispatch(): mixed
{ {
try {
Context::setContext('dispatch-param', func_get_args()); Context::setContext('dispatch-param', func_get_args());
if (empty($this->callback)) { if (empty($this->callback)) {
return Json::to(404, $this->errorMsg()); return Json::to(404, $this->errorMsg());
} }
return $this->httpFilter(); return $this->httpFilter();
} catch (Throwable $throwable) {
$this->addError($throwable, 'throwable');
$code = $throwable->getCode() == 0 ? 500 : $throwable->getCode();
return Json::to($code, $throwable->getMessage());
}
} }
@@ -529,19 +537,11 @@ 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());
}
} }