1
我有这个函数可以得到URLS的状态码,如果提供了一个虚假的URL,它只是通过例外说“假url”。我想处理这个异常,并像404一样对待,该网站已关闭。laravel:异常处理
private function getStatusCode($url)
{
$response = $this->client->get($url, [
'http_errors' => false
]);
return $response->getStatusCode();
}
我试过这段代码,但没有帮助。我需要你的帮助来弄明白吗?
private function getStatusCode($url)
{
try{
$response = $this->client->get($url, [
'http_errors' => false
]);
return $response->getStatusCode();
}
//catch specific exception....
catch(QueryException $e)
{
//...and do whatever you want
return $response;
}
}