From a543da2ba25339f1b3a5982ccf197b622fbc8361 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 29 Jul 2026 11:23:33 +0200 Subject: [PATCH 1/2] Add support for guzzle 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 53e05d80..eb059c1e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": { "php": "^8.2", "ext-curl": "^8.2", - "guzzlehttp/guzzle": "^7.0", + "guzzlehttp/guzzle": "^7.0 || ^8.0", "paragonie/halite": "^5.1" }, "require-dev": { From e9ebe1c9d776a8e90b4ec63e41a7d6375a8b12d1 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 29 Jul 2026 11:40:13 +0200 Subject: [PATCH 2/2] Add BC layer --- lib/HttpClient.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/HttpClient.php b/lib/HttpClient.php index ad7f94ab..432db628 100644 --- a/lib/HttpClient.php +++ b/lib/HttpClient.php @@ -8,7 +8,9 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\ConnectTimeoutException; use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Exception\ResponseException; use Psr\Http\Message\ResponseInterface; use WorkOS\Exception\ApiException; use WorkOS\Exception\AuthenticationException; @@ -120,17 +122,22 @@ public function request( throw $this->mapTransportException($e); } catch (RequestException $e) { - if ($e->hasResponse()) { + $response = null; + if ($e instanceof ResponseException) { $response = $e->getResponse(); - if ($response !== null) { - $statusCode = $response->getStatusCode(); - if (in_array($statusCode, self::RETRY_STATUS_CODES, true) && $attempt < $maxRetries) { - $this->sleep($attempt, $response->getHeaderLine('Retry-After')); - continue; - } - - throw $this->mapApiException($response, $e); + } elseif (method_exists($e, 'getResponse')) { + // BC layer for guzzle 7 + $response = $e->getResponse(); + } + + if ($response instanceof ResponseInterface) { + $statusCode = $response->getStatusCode(); + if (in_array($statusCode, self::RETRY_STATUS_CODES, true) && $attempt < $maxRetries) { + $this->sleep($attempt, $response->getHeaderLine('Retry-After')); + continue; } + + throw $this->mapApiException($response, $e); } if ($attempt < $maxRetries) { @@ -417,10 +424,17 @@ private function mapTransportException(\Throwable $exception): \Exception private function isTimeoutException(\Throwable $exception): bool { if ($exception instanceof ConnectException || $exception instanceof RequestException) { - $errno = $exception->getHandlerContext()['errno'] ?? null; - if ($errno === 28) { + if ($exception instanceof ConnectTimeoutException) { return true; } + + if (method_exists($exception, 'getHandlerContext')) { + // BC layer for guzzle 7 + $errno = $exception->getHandlerContext()['errno'] ?? null; + if ($errno === 28) { + return true; + } + } } return str_contains(strtolower($exception->getMessage()), 'timed out');