如何处理致命错误:cURL错误7:无法连接到xxxx端口443

2025-05-12 01:31:36
推荐回答(1个)
回答(1):

From Michael's comment
it looks like you can just catch the GuzzleHttp\Ring\Exception\ConnectException exception
like this:
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;
}
}

it appears guzzle's ConnectException extends some classes and ultimately extends php's Exception so you can safely use the getCode() method, allowing you to catch an identifier on which you can react accordingly to your needs.