Namespace: GuzzleHttp\Exception
Extends: GuzzleHttp\Exception\TransferException
Implements: GuzzleHttp\Exception\NetworkExceptionInterface
Exception thrown when a connection cannot be established to the remote server. This exception is thrown by Guzzle HTTP client when there are network connectivity issues.
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ConnectException;
try {
$client = new Client();
$response = $client->request('GET', 'https://api.example.com/endpoint');
} catch (ConnectException $e) {
// Handle connection errors
echo "Connection error: " . $e->getMessage();
// Get the request that caused the exception
$request = $e->getRequest();
// Get the handlerContext for more details about the error
$context = $e->getHandlerContext();
}- DNS resolution failures
- Network connectivity issues
- Firewall blocking the connection
- Server is down or unreachable
- SSL/TLS certificate issues
- Timeout while establishing the connection
- Proxy configuration issues
- Check your network connectivity
- Verify the hostname is correct and can be resolved
- Check if the server is running and accessible
- Verify firewall settings are not blocking the connection
- Check SSL/TLS certificate validity
- Increase connection timeout settings if needed
- Verify proxy settings if using a proxy
public function __construct(
string $message,
\Psr\Http\Message\RequestInterface $request,
\Throwable $previous = null,
array $handlerContext = []
)| Name | Type | Description |
|---|---|---|
$message |
string | The error message |
$request |
\Psr\Http\Message\RequestInterface | The request that caused the exception |
$previous |
\Throwable | Previous exception (if applicable) |
$handlerContext |
array | Handler context containing additional error details |
Returns the request that caused the exception.
public function getRequest(): \Psr\Http\Message\RequestInterfaceReturns the handler context array.
public function getHandlerContext(): array