修改后的代码如下所示:
public function check($url, $must = false)
{
// 自动检测域名路由
$domain = $this->checkDomain();
$url = str_replace($this->config['pathinfo_depr'], '|', $url);
$completeMatch = $this->config['route_complete_match'];
$result = $domain->check($this->request, $url, $completeMatch);
if (false === $result && !empty($this->cross)) {
// 检测跨域路由
$result = $this->cross->check($this->request, $url, $completeMatch);
}
if (false !== $result) {
// 路由匹配
return $result;
} elseif ($must) {
// 强制路由不匹配则返回默认错误信息
return "404 Not Found";
}
// 默认路由解析
return new UrlDispatch($this->request, $this->group, $url, [
'auto_search' => $this->autoSearchController,
]);
}
修改后的代码中,在elseif ($must)
条件下,将抛出异常的代码改为返回一个默认的错误信息,即return "404 Not Found";
。这样就屏蔽了爆出代码的情况,而是显示了一个固定的错误提示信息。