use GuzzleHttp\Ring\Exception\ConnectException;
try {
// the code which throws the error
} catch( ConnectException $ex ) {
switch ( $ex->getMessage() ) {
case '7': // to be verified
// handle your exception in the way you want,
// maybe with a graceful fallback
break;
}
}
use Illuminate\Http\Client\ConnectionException;
...
try {
Http::get('<your url>');
}
catch (ConnectionException $e) {
// Do something with $e for example Log::debug($e->getMessage());
}
2条答案
按热度按时间prdp8dxp1#
来自Michael's注解
看起来您可以捕获GuzzleHttp\Ring\Exception\ConnectException异常
像这样:
它看起来像是guzzle的ConnectExceptionextendssomeclasses,并最终扩展了php的Exception,这样您就可以安全地使用getCode()方法,允许您捕获一个标识符,您可以根据需要对该标识符做出React。
0g0grzrc2#
捕获ConnectionException,示例代码如下: