diff --git a/.github/workflows/phpspec.yml b/.github/workflows/phpspec.yml index ba0fb1aeb..479f7d309 100644 --- a/.github/workflows/phpspec.yml +++ b/.github/workflows/phpspec.yml @@ -6,11 +6,22 @@ jobs: build: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + guzzle: ['^7.3', '^8.0'] + + name: "phpspec (guzzle ${{ matrix.guzzle }})" + + env: + GUZZLE_CONSTRAINT: ${{ matrix.guzzle }} + steps: - uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' - - run: composer install + - run: composer require "guzzlehttp/guzzle:$GUZZLE_CONSTRAINT" --no-update --no-interaction + - run: composer update --no-interaction --no-progress - run: vendor/bin/phpspec run diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index c1dac1f7d..471390f43 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -6,11 +6,22 @@ jobs: build: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + guzzle: ['^7.3', '^8.0'] + + name: "phpunit (guzzle ${{ matrix.guzzle }})" + + env: + GUZZLE_CONSTRAINT: ${{ matrix.guzzle }} + steps: - uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' - - run: composer install + - run: composer require "guzzlehttp/guzzle:$GUZZLE_CONSTRAINT" --no-update --no-interaction + - run: composer update --no-interaction --no-progress - run: vendor/bin/phpunit ./tests diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd6dc2a1..2ee95970f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/HubSpot/hubspot-api-php/compare/14.1.0...HEAD) +### Guzzle 8 support + +- `guzzlehttp/guzzle` `^8.0` and `guzzlehttp/psr7` `^3.0` are now allowed; Guzzle 7 remains supported. +- Generated clients no longer call the removed `\GuzzleHttp\Utils::jsonEncode()`; they use `json_encode(..., JSON_THROW_ON_ERROR)`. +- Generated clients no longer assume `RequestException::getResponse()` exists (removed in Guzzle 8, where only `ResponseException` subclasses carry a response). Failures without a response now produce an `ApiException` with `null` headers/body instead of a fatal error, on both the sync and async paths. +- Generated clients catch `Psr\Http\Client\NetworkExceptionInterface` instead of `GuzzleHttp\Exception\ConnectException`, so Guzzle 8's `NetworkException` (send/receive errors, HTTP/2 and HTTP/3 failures) is still converted to an `ApiException`. +- `RetryMiddlewareFactory::getRetryFunctionByConnectionErrors()` now matches `Psr\Http\Client\NetworkExceptionInterface` and reads the cURL errno from handler context when available, falling back to the exception message because Guzzle 8 removed `RequestException::getHandlerContext()` and reclassified cURL errors 52, 55 and 56 as `NetworkException` rather than `ConnectException`. Guzzle 7 send/receive failures (cURL errors 55 and 56) are also retried by recognizing `RequestException` with matching cURL handler context. +- `apiRequest()` uppercases the `method` option. Guzzle 7 uppercased request methods, Guzzle 8 sends them verbatim. +- The retry decider callbacks accept any PSR-7 `RequestInterface`/`ResponseInterface` instead of only `GuzzleHttp\Psr7\Request`/`Response`. + ## [14.1.0](https://github.com/HubSpot/hubspot-api-php/releases/tag/14.1.0) - 2026-05-12 ### Retry Middleware diff --git a/README.md b/README.md index ec4b34783..339629d36 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ The current package requirements are: PHP >= 8.1 +Guzzle 7 and Guzzle 8 are both supported (`guzzlehttp/guzzle: ^7.3 || ^8.0`). + ### Sample apps Please, take a look at our [Sample apps](https://github.com/HubSpot/sample-apps-list) diff --git a/codegen/Cms/AuditLogs/Api/AuditLogsApi.php b/codegen/Cms/AuditLogs/Api/AuditLogsApi.php index f2bb5454f..cdff1e560 100644 --- a/codegen/Cms/AuditLogs/Api/AuditLogsApi.php +++ b/codegen/Cms/AuditLogs/Api/AuditLogsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\AuditLogs\ApiException; @@ -178,13 +178,16 @@ public function getPageWithHttpInfo($user_id = null, $event_type = null, $object try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -327,8 +330,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -336,8 +340,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -478,7 +482,7 @@ public function getPageRequest($user_id = null, $event_type = null, $object_type } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/Blogs/Authors/Api/BlogAuthorsApi.php b/codegen/Cms/Blogs/Authors/Api/BlogAuthorsApi.php index 6621db690..79990cba2 100644 --- a/codegen/Cms/Blogs/Authors/Api/BlogAuthorsApi.php +++ b/codegen/Cms/Blogs/Authors/Api/BlogAuthorsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\Blogs\Authors\ApiException; @@ -204,13 +204,16 @@ public function archiveWithHttpInfo($object_id, $archived = null, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -286,8 +289,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -295,8 +299,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -376,7 +380,7 @@ public function archiveRequest($object_id, $archived = null, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -447,13 +451,16 @@ public function archiveBatchWithHttpInfo($batch_input_string, string $contentTyp try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -527,8 +534,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -536,8 +544,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -584,7 +592,7 @@ public function archiveBatchRequest($batch_input_string, string $contentType = s if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -605,7 +613,7 @@ public function archiveBatchRequest($batch_input_string, string $contentType = s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -676,13 +684,16 @@ public function attachToLangGroupWithHttpInfo($attach_to_lang_primary_request_v_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -756,8 +767,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -765,8 +777,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -813,7 +825,7 @@ public function attachToLangGroupRequest($attach_to_lang_primary_request_v_next, if (isset($attach_to_lang_primary_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($attach_to_lang_primary_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($attach_to_lang_primary_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $attach_to_lang_primary_request_v_next; } @@ -834,7 +846,7 @@ public function attachToLangGroupRequest($attach_to_lang_primary_request_v_next, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -906,13 +918,16 @@ public function createWithHttpInfo($blog_author, string $contentType = self::con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1041,8 +1056,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1050,8 +1066,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1098,7 +1114,7 @@ public function createRequest($blog_author, string $contentType = self::contentT if (isset($blog_author)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($blog_author)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_author), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_author; } @@ -1119,7 +1135,7 @@ public function createRequest($blog_author, string $contentType = self::contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1191,13 +1207,16 @@ public function createBatchWithHttpInfo($batch_input_blog_author, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1340,8 +1359,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1349,8 +1369,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1397,7 +1417,7 @@ public function createBatchRequest($batch_input_blog_author, string $contentType if (isset($batch_input_blog_author)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_blog_author)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_blog_author), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_blog_author; } @@ -1418,7 +1438,7 @@ public function createBatchRequest($batch_input_blog_author, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1490,13 +1510,16 @@ public function createLangVariationWithHttpInfo($blog_author_clone_request_v_nex try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1625,8 +1648,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1634,8 +1658,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1682,7 +1706,7 @@ public function createLangVariationRequest($blog_author_clone_request_v_next, st if (isset($blog_author_clone_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($blog_author_clone_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_author_clone_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_author_clone_request_v_next; } @@ -1703,7 +1727,7 @@ public function createLangVariationRequest($blog_author_clone_request_v_next, st } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1774,13 +1798,16 @@ public function detachFromLangGroupWithHttpInfo($detach_from_lang_group_request_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1854,8 +1881,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1863,8 +1891,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1911,7 +1939,7 @@ public function detachFromLangGroupRequest($detach_from_lang_group_request_v_nex if (isset($detach_from_lang_group_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($detach_from_lang_group_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($detach_from_lang_group_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $detach_from_lang_group_request_v_next; } @@ -1932,7 +1960,7 @@ public function detachFromLangGroupRequest($detach_from_lang_group_request_v_nex } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2008,13 +2036,16 @@ public function getByIdWithHttpInfo($object_id, $archived = null, $property = nu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2147,8 +2178,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2156,8 +2188,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2248,7 +2280,7 @@ public function getByIdRequest($object_id, $archived = null, $property = null, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2340,13 +2372,16 @@ public function getPageWithHttpInfo($created_at = null, $created_after = null, $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2495,8 +2530,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2504,8 +2540,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2679,7 +2715,7 @@ public function getPageRequest($created_at = null, $created_after = null, $creat } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2753,13 +2789,16 @@ public function readBatchWithHttpInfo($batch_input_string, $archived = null, str try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2904,8 +2943,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2913,8 +2953,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2972,7 +3012,7 @@ public function readBatchRequest($batch_input_string, $archived = null, string $ if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -2993,7 +3033,7 @@ public function readBatchRequest($batch_input_string, $archived = null, string $ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3064,13 +3104,16 @@ public function setLangPrimaryWithHttpInfo($set_new_language_primary_request_v_n try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3144,8 +3187,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3153,8 +3197,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3201,7 +3245,7 @@ public function setLangPrimaryRequest($set_new_language_primary_request_v_next, if (isset($set_new_language_primary_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($set_new_language_primary_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($set_new_language_primary_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $set_new_language_primary_request_v_next; } @@ -3222,7 +3266,7 @@ public function setLangPrimaryRequest($set_new_language_primary_request_v_next, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3298,13 +3342,16 @@ public function updateWithHttpInfo($object_id, $blog_author, $archived = null, s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3437,8 +3484,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3446,8 +3494,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3521,7 +3569,7 @@ public function updateRequest($object_id, $blog_author, $archived = null, string if (isset($blog_author)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($blog_author)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_author), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_author; } @@ -3542,7 +3590,7 @@ public function updateRequest($object_id, $blog_author, $archived = null, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3616,13 +3664,16 @@ public function updateBatchWithHttpInfo($batch_input_json_node, $archived = null try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3767,8 +3818,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3776,8 +3828,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3835,7 +3887,7 @@ public function updateBatchRequest($batch_input_json_node, $archived = null, str if (isset($batch_input_json_node)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_json_node)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_json_node), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_json_node; } @@ -3856,7 +3908,7 @@ public function updateBatchRequest($batch_input_json_node, $archived = null, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3927,13 +3979,16 @@ public function updateLangsWithHttpInfo($update_languages_request_v_next, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -4007,8 +4062,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -4016,8 +4072,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4064,7 +4120,7 @@ public function updateLangsRequest($update_languages_request_v_next, string $con if (isset($update_languages_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($update_languages_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($update_languages_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $update_languages_request_v_next; } @@ -4085,7 +4141,7 @@ public function updateLangsRequest($update_languages_request_v_next, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/Blogs/Tags/Api/BlogTagsApi.php b/codegen/Cms/Blogs/Tags/Api/BlogTagsApi.php index 7a993eabd..6f0d1ee10 100644 --- a/codegen/Cms/Blogs/Tags/Api/BlogTagsApi.php +++ b/codegen/Cms/Blogs/Tags/Api/BlogTagsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\Blogs\Tags\ApiException; @@ -204,13 +204,16 @@ public function archiveWithHttpInfo($object_id, $archived = null, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -286,8 +289,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -295,8 +299,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -376,7 +380,7 @@ public function archiveRequest($object_id, $archived = null, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -447,13 +451,16 @@ public function archiveBatchWithHttpInfo($batch_input_string, string $contentTyp try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -527,8 +534,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -536,8 +544,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -584,7 +592,7 @@ public function archiveBatchRequest($batch_input_string, string $contentType = s if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -605,7 +613,7 @@ public function archiveBatchRequest($batch_input_string, string $contentType = s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -676,13 +684,16 @@ public function attachToLangGroupWithHttpInfo($attach_to_lang_primary_request_v_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -756,8 +767,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -765,8 +777,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -813,7 +825,7 @@ public function attachToLangGroupRequest($attach_to_lang_primary_request_v_next, if (isset($attach_to_lang_primary_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($attach_to_lang_primary_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($attach_to_lang_primary_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $attach_to_lang_primary_request_v_next; } @@ -834,7 +846,7 @@ public function attachToLangGroupRequest($attach_to_lang_primary_request_v_next, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -906,13 +918,16 @@ public function createWithHttpInfo($tag, string $contentType = self::contentType try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1041,8 +1056,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1050,8 +1066,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1098,7 +1114,7 @@ public function createRequest($tag, string $contentType = self::contentTypes['cr if (isset($tag)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($tag)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($tag), JSON_THROW_ON_ERROR); } else { $httpBody = $tag; } @@ -1119,7 +1135,7 @@ public function createRequest($tag, string $contentType = self::contentTypes['cr } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1191,13 +1207,16 @@ public function createBatchWithHttpInfo($batch_input_tag, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1340,8 +1359,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1349,8 +1369,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1397,7 +1417,7 @@ public function createBatchRequest($batch_input_tag, string $contentType = self: if (isset($batch_input_tag)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_tag)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_tag), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_tag; } @@ -1418,7 +1438,7 @@ public function createBatchRequest($batch_input_tag, string $contentType = self: } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1490,13 +1510,16 @@ public function createLangVariationWithHttpInfo($tag_clone_request_v_next, strin try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1625,8 +1648,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1634,8 +1658,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1682,7 +1706,7 @@ public function createLangVariationRequest($tag_clone_request_v_next, string $co if (isset($tag_clone_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($tag_clone_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($tag_clone_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $tag_clone_request_v_next; } @@ -1703,7 +1727,7 @@ public function createLangVariationRequest($tag_clone_request_v_next, string $co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1774,13 +1798,16 @@ public function detachFromLangGroupWithHttpInfo($detach_from_lang_group_request_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1854,8 +1881,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1863,8 +1891,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1911,7 +1939,7 @@ public function detachFromLangGroupRequest($detach_from_lang_group_request_v_nex if (isset($detach_from_lang_group_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($detach_from_lang_group_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($detach_from_lang_group_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $detach_from_lang_group_request_v_next; } @@ -1932,7 +1960,7 @@ public function detachFromLangGroupRequest($detach_from_lang_group_request_v_nex } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2008,13 +2036,16 @@ public function getByIdWithHttpInfo($object_id, $archived = null, $property = nu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2147,8 +2178,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2156,8 +2188,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2248,7 +2280,7 @@ public function getByIdRequest($object_id, $archived = null, $property = null, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2340,13 +2372,16 @@ public function getPageWithHttpInfo($created_at = null, $created_after = null, $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2495,8 +2530,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2504,8 +2540,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2679,7 +2715,7 @@ public function getPageRequest($created_at = null, $created_after = null, $creat } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2753,13 +2789,16 @@ public function readBatchWithHttpInfo($batch_input_string, $archived = null, str try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2904,8 +2943,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2913,8 +2953,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2972,7 +3012,7 @@ public function readBatchRequest($batch_input_string, $archived = null, string $ if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -2993,7 +3033,7 @@ public function readBatchRequest($batch_input_string, $archived = null, string $ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3064,13 +3104,16 @@ public function setLangPrimaryWithHttpInfo($set_new_language_primary_request_v_n try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3144,8 +3187,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3153,8 +3197,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3201,7 +3245,7 @@ public function setLangPrimaryRequest($set_new_language_primary_request_v_next, if (isset($set_new_language_primary_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($set_new_language_primary_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($set_new_language_primary_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $set_new_language_primary_request_v_next; } @@ -3222,7 +3266,7 @@ public function setLangPrimaryRequest($set_new_language_primary_request_v_next, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3298,13 +3342,16 @@ public function updateWithHttpInfo($object_id, $tag, $archived = null, string $c try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3437,8 +3484,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3446,8 +3494,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3521,7 +3569,7 @@ public function updateRequest($object_id, $tag, $archived = null, string $conten if (isset($tag)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($tag)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($tag), JSON_THROW_ON_ERROR); } else { $httpBody = $tag; } @@ -3542,7 +3590,7 @@ public function updateRequest($object_id, $tag, $archived = null, string $conten } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3616,13 +3664,16 @@ public function updateBatchWithHttpInfo($batch_input_json_node, $archived = null try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3767,8 +3818,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3776,8 +3828,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3835,7 +3887,7 @@ public function updateBatchRequest($batch_input_json_node, $archived = null, str if (isset($batch_input_json_node)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_json_node)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_json_node), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_json_node; } @@ -3856,7 +3908,7 @@ public function updateBatchRequest($batch_input_json_node, $archived = null, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3927,13 +3979,16 @@ public function updateLangsWithHttpInfo($update_languages_request_v_next, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -4007,8 +4062,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -4016,8 +4072,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4064,7 +4120,7 @@ public function updateLangsRequest($update_languages_request_v_next, string $con if (isset($update_languages_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($update_languages_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($update_languages_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $update_languages_request_v_next; } @@ -4085,7 +4141,7 @@ public function updateLangsRequest($update_languages_request_v_next, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/Domains/Api/DomainsApi.php b/codegen/Cms/Domains/Api/DomainsApi.php index 2f4df9830..f8ff0c8e1 100644 --- a/codegen/Cms/Domains/Api/DomainsApi.php +++ b/codegen/Cms/Domains/Api/DomainsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\Domains\ApiException; @@ -167,13 +167,16 @@ public function getByIdWithHttpInfo($domain_id, string $contentType = self::cont try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -302,8 +305,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -311,8 +315,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -381,7 +385,7 @@ public function getByIdRequest($domain_id, string $contentType = self::contentTy } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -471,13 +475,16 @@ public function getPageWithHttpInfo($created_at = null, $created_after = null, $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -624,8 +631,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -633,8 +641,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -797,7 +805,7 @@ public function getPageRequest($created_at = null, $created_after = null, $creat } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/Hubdb/Api/RowsBatchApi.php b/codegen/Cms/Hubdb/Api/RowsBatchApi.php index d7953dc46..007a3bfdc 100644 --- a/codegen/Cms/Hubdb/Api/RowsBatchApi.php +++ b/codegen/Cms/Hubdb/Api/RowsBatchApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\Hubdb\ApiException; @@ -184,13 +184,16 @@ public function cloneDraftTableRowsWithHttpInfo($table_id_or_name, $batch_input_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -321,8 +324,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -330,8 +334,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -394,7 +398,7 @@ public function cloneDraftTableRowsRequest($table_id_or_name, $batch_input_hub_d if (isset($batch_input_hub_db_table_row_batch_clone_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_batch_clone_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_batch_clone_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_hub_db_table_row_batch_clone_request; } @@ -415,7 +419,7 @@ public function cloneDraftTableRowsRequest($table_id_or_name, $batch_input_hub_d } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -489,13 +493,16 @@ public function createDraftTableRowsWithHttpInfo($table_id_or_name, $batch_input try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -640,8 +647,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -649,8 +657,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -713,7 +721,7 @@ public function createDraftTableRowsRequest($table_id_or_name, $batch_input_hub_ if (isset($batch_input_hub_db_table_row_v3_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_v3_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_v3_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_hub_db_table_row_v3_request; } @@ -734,7 +742,7 @@ public function createDraftTableRowsRequest($table_id_or_name, $batch_input_hub_ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -807,13 +815,16 @@ public function purgeDraftTableRowsWithHttpInfo($table_id_or_name, $batch_input_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -889,8 +900,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -898,8 +910,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -962,7 +974,7 @@ public function purgeDraftTableRowsRequest($table_id_or_name, $batch_input_strin if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -983,7 +995,7 @@ public function purgeDraftTableRowsRequest($table_id_or_name, $batch_input_strin } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1057,13 +1069,16 @@ public function readDraftTableRowsWithHttpInfo($table_id_or_name, $batch_input_s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1208,8 +1223,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1217,8 +1233,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1281,7 +1297,7 @@ public function readDraftTableRowsRequest($table_id_or_name, $batch_input_string if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -1302,7 +1318,7 @@ public function readDraftTableRowsRequest($table_id_or_name, $batch_input_string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1376,13 +1392,16 @@ public function readTableRowsWithHttpInfo($table_id_or_name, $batch_input_string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1527,8 +1546,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1536,8 +1556,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1600,7 +1620,7 @@ public function readTableRowsRequest($table_id_or_name, $batch_input_string, str if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -1621,7 +1641,7 @@ public function readTableRowsRequest($table_id_or_name, $batch_input_string, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1695,13 +1715,16 @@ public function replaceDraftTableRowsWithHttpInfo($table_id_or_name, $batch_inpu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1846,8 +1869,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1855,8 +1879,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1919,7 +1943,7 @@ public function replaceDraftTableRowsRequest($table_id_or_name, $batch_input_hub if (isset($batch_input_hub_db_table_row_v3_batch_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_v3_batch_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_v3_batch_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_hub_db_table_row_v3_batch_update_request; } @@ -1940,7 +1964,7 @@ public function replaceDraftTableRowsRequest($table_id_or_name, $batch_input_hub } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2014,13 +2038,16 @@ public function updateDraftTableRowsWithHttpInfo($table_id_or_name, $batch_input try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2165,8 +2192,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2174,8 +2202,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2238,7 +2266,7 @@ public function updateDraftTableRowsRequest($table_id_or_name, $batch_input_hub_ if (isset($batch_input_hub_db_table_row_v3_batch_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_v3_batch_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_hub_db_table_row_v3_batch_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_hub_db_table_row_v3_batch_update_request; } @@ -2259,7 +2287,7 @@ public function updateDraftTableRowsRequest($table_id_or_name, $batch_input_hub_ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/Pages/Api/SitePagesApi.php b/codegen/Cms/Pages/Api/SitePagesApi.php index 3306ba04b..f2d93f4d4 100644 --- a/codegen/Cms/Pages/Api/SitePagesApi.php +++ b/codegen/Cms/Pages/Api/SitePagesApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\Pages\ApiException; @@ -243,13 +243,16 @@ public function archiveWithHttpInfo($object_id, $archived = null, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -325,8 +328,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -334,8 +338,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -415,7 +419,7 @@ public function archiveRequest($object_id, $archived = null, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -486,13 +490,16 @@ public function archiveBatchWithHttpInfo($batch_input_string, string $contentTyp try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -566,8 +573,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -575,8 +583,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -623,7 +631,7 @@ public function archiveBatchRequest($batch_input_string, string $contentType = s if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -644,7 +652,7 @@ public function archiveBatchRequest($batch_input_string, string $contentType = s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -715,13 +723,16 @@ public function attachToLangGroupWithHttpInfo($attach_to_lang_primary_request_v_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -795,8 +806,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -804,8 +816,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -852,7 +864,7 @@ public function attachToLangGroupRequest($attach_to_lang_primary_request_v_next, if (isset($attach_to_lang_primary_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($attach_to_lang_primary_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($attach_to_lang_primary_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $attach_to_lang_primary_request_v_next; } @@ -873,7 +885,7 @@ public function attachToLangGroupRequest($attach_to_lang_primary_request_v_next, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -945,13 +957,16 @@ public function callCloneWithHttpInfo($content_clone_request_v_next, string $con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1080,8 +1095,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1089,8 +1105,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1137,7 +1153,7 @@ public function callCloneRequest($content_clone_request_v_next, string $contentT if (isset($content_clone_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($content_clone_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($content_clone_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $content_clone_request_v_next; } @@ -1158,7 +1174,7 @@ public function callCloneRequest($content_clone_request_v_next, string $contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1229,13 +1245,16 @@ public function createWithHttpInfo($page, string $contentType = self::contentTyp try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1317,8 +1336,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1326,8 +1346,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1374,7 +1394,7 @@ public function createRequest($page, string $contentType = self::contentTypes['c if (isset($page)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($page)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($page), JSON_THROW_ON_ERROR); } else { $httpBody = $page; } @@ -1395,7 +1415,7 @@ public function createRequest($page, string $contentType = self::contentTypes['c } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1467,13 +1487,16 @@ public function createABTestVariationWithHttpInfo($ab_test_create_request_v_next try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1602,8 +1625,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1611,8 +1635,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1659,7 +1683,7 @@ public function createABTestVariationRequest($ab_test_create_request_v_next, str if (isset($ab_test_create_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($ab_test_create_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($ab_test_create_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $ab_test_create_request_v_next; } @@ -1680,7 +1704,7 @@ public function createABTestVariationRequest($ab_test_create_request_v_next, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1752,13 +1776,16 @@ public function createBatchWithHttpInfo($batch_input_page, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1901,8 +1928,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1910,8 +1938,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1958,7 +1986,7 @@ public function createBatchRequest($batch_input_page, string $contentType = self if (isset($batch_input_page)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_page)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_page), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_page; } @@ -1979,7 +2007,7 @@ public function createBatchRequest($batch_input_page, string $contentType = self } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2051,13 +2079,16 @@ public function createLangVariationWithHttpInfo($content_language_clone_request_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2186,8 +2217,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2195,8 +2227,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2243,7 +2275,7 @@ public function createLangVariationRequest($content_language_clone_request_v_nex if (isset($content_language_clone_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($content_language_clone_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($content_language_clone_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $content_language_clone_request_v_next; } @@ -2264,7 +2296,7 @@ public function createLangVariationRequest($content_language_clone_request_v_nex } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2335,13 +2367,16 @@ public function detachFromLangGroupWithHttpInfo($detach_from_lang_group_request_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2415,8 +2450,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2424,8 +2460,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2472,7 +2508,7 @@ public function detachFromLangGroupRequest($detach_from_lang_group_request_v_nex if (isset($detach_from_lang_group_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($detach_from_lang_group_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($detach_from_lang_group_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $detach_from_lang_group_request_v_next; } @@ -2493,7 +2529,7 @@ public function detachFromLangGroupRequest($detach_from_lang_group_request_v_nex } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2564,13 +2600,16 @@ public function endActiveABTestWithHttpInfo($ab_test_end_request_v_next, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2644,8 +2683,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2653,8 +2693,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2701,7 +2741,7 @@ public function endActiveABTestRequest($ab_test_end_request_v_next, string $cont if (isset($ab_test_end_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($ab_test_end_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($ab_test_end_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $ab_test_end_request_v_next; } @@ -2722,7 +2762,7 @@ public function endActiveABTestRequest($ab_test_end_request_v_next, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2798,13 +2838,16 @@ public function getByIdWithHttpInfo($object_id, $archived = null, $property = nu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2937,8 +2980,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2946,8 +2990,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3038,7 +3082,7 @@ public function getByIdRequest($object_id, $archived = null, $property = null, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3110,13 +3154,16 @@ public function getDraftByIdWithHttpInfo($object_id, string $contentType = self: try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3245,8 +3292,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3254,8 +3302,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3324,7 +3372,7 @@ public function getDraftByIdRequest($object_id, string $contentType = self::cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3416,13 +3464,16 @@ public function getPageWithHttpInfo($created_at = null, $created_after = null, $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3571,8 +3622,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3580,8 +3632,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3755,7 +3807,7 @@ public function getPageRequest($created_at = null, $created_after = null, $creat } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -3829,13 +3881,16 @@ public function getPreviousVersionWithHttpInfo($object_id, $revision_id, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -3966,8 +4021,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -3975,8 +4031,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4061,7 +4117,7 @@ public function getPreviousVersionRequest($object_id, $revision_id, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -4139,13 +4195,16 @@ public function getPreviousVersionsWithHttpInfo($object_id, $after = null, $befo try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -4280,8 +4339,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -4289,8 +4349,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4392,7 +4452,7 @@ public function getPreviousVersionsRequest($object_id, $after = null, $before = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -4463,13 +4523,16 @@ public function pushLiveWithHttpInfo($object_id, string $contentType = self::con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -4543,8 +4606,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -4552,8 +4616,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4622,7 +4686,7 @@ public function pushLiveRequest($object_id, string $contentType = self::contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -4696,13 +4760,16 @@ public function readBatchWithHttpInfo($batch_input_string, $archived = null, str try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -4847,8 +4914,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -4856,8 +4924,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4915,7 +4983,7 @@ public function readBatchRequest($batch_input_string, $archived = null, string $ if (isset($batch_input_string)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_string)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_string), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_string; } @@ -4936,7 +5004,7 @@ public function readBatchRequest($batch_input_string, $archived = null, string $ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -5007,13 +5075,16 @@ public function rerunPreviousABTestWithHttpInfo($ab_test_rerun_request_v_next, s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -5087,8 +5158,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -5096,8 +5168,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5144,7 +5216,7 @@ public function rerunPreviousABTestRequest($ab_test_rerun_request_v_next, string if (isset($ab_test_rerun_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($ab_test_rerun_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($ab_test_rerun_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $ab_test_rerun_request_v_next; } @@ -5165,7 +5237,7 @@ public function rerunPreviousABTestRequest($ab_test_rerun_request_v_next, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -5236,13 +5308,16 @@ public function resetDraftWithHttpInfo($object_id, string $contentType = self::c try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -5316,8 +5391,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -5325,8 +5401,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5395,7 +5471,7 @@ public function resetDraftRequest($object_id, string $contentType = self::conten } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -5469,13 +5545,16 @@ public function restorePreviousVersionWithHttpInfo($object_id, $revision_id, str try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -5606,8 +5685,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -5615,8 +5695,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5701,7 +5781,7 @@ public function restorePreviousVersionRequest($object_id, $revision_id, string $ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -5775,13 +5855,16 @@ public function restorePreviousVersionToDraftWithHttpInfo($object_id, $revision_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -5912,8 +5995,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -5921,8 +6005,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6007,7 +6091,7 @@ public function restorePreviousVersionToDraftRequest($object_id, $revision_id, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -6078,13 +6162,16 @@ public function scheduleWithHttpInfo($content_schedule_request_v_next, string $c try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -6158,8 +6245,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -6167,8 +6255,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6215,7 +6303,7 @@ public function scheduleRequest($content_schedule_request_v_next, string $conten if (isset($content_schedule_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($content_schedule_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($content_schedule_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $content_schedule_request_v_next; } @@ -6236,7 +6324,7 @@ public function scheduleRequest($content_schedule_request_v_next, string $conten } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -6307,13 +6395,16 @@ public function setLangPrimaryWithHttpInfo($set_new_language_primary_request_v_n try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -6387,8 +6478,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -6396,8 +6488,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6444,7 +6536,7 @@ public function setLangPrimaryRequest($set_new_language_primary_request_v_next, if (isset($set_new_language_primary_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($set_new_language_primary_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($set_new_language_primary_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $set_new_language_primary_request_v_next; } @@ -6465,7 +6557,7 @@ public function setLangPrimaryRequest($set_new_language_primary_request_v_next, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -6541,13 +6633,16 @@ public function updateWithHttpInfo($object_id, $page, $archived = null, string $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -6680,8 +6775,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -6689,8 +6785,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6764,7 +6860,7 @@ public function updateRequest($object_id, $page, $archived = null, string $conte if (isset($page)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($page)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($page), JSON_THROW_ON_ERROR); } else { $httpBody = $page; } @@ -6785,7 +6881,7 @@ public function updateRequest($object_id, $page, $archived = null, string $conte } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -6859,13 +6955,16 @@ public function updateBatchWithHttpInfo($batch_input_json_node, $archived = null try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -7010,8 +7109,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -7019,8 +7119,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7078,7 +7178,7 @@ public function updateBatchRequest($batch_input_json_node, $archived = null, str if (isset($batch_input_json_node)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_json_node)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_json_node), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_json_node; } @@ -7099,7 +7199,7 @@ public function updateBatchRequest($batch_input_json_node, $archived = null, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -7173,13 +7273,16 @@ public function updateDraftWithHttpInfo($object_id, $page, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -7310,8 +7413,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -7319,8 +7423,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7383,7 +7487,7 @@ public function updateDraftRequest($object_id, $page, string $contentType = self if (isset($page)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($page)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($page), JSON_THROW_ON_ERROR); } else { $httpBody = $page; } @@ -7404,7 +7508,7 @@ public function updateDraftRequest($object_id, $page, string $contentType = self } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -7475,13 +7579,16 @@ public function updateLangsWithHttpInfo($update_languages_request_v_next, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -7555,8 +7662,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -7564,8 +7672,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7612,7 +7720,7 @@ public function updateLangsRequest($update_languages_request_v_next, string $con if (isset($update_languages_request_v_next)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($update_languages_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($update_languages_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $update_languages_request_v_next; } @@ -7633,7 +7741,7 @@ public function updateLangsRequest($update_languages_request_v_next, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/SiteSearch/Api/PublicApi.php b/codegen/Cms/SiteSearch/Api/PublicApi.php index b6d09e928..feaebaafb 100644 --- a/codegen/Cms/SiteSearch/Api/PublicApi.php +++ b/codegen/Cms/SiteSearch/Api/PublicApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\SiteSearch\ApiException; @@ -169,13 +169,16 @@ public function getByIdWithHttpInfo($content_id, $type = null, string $contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -306,8 +309,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -315,8 +319,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -399,7 +403,7 @@ public function getByIdRequest($content_id, $type = null, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -503,13 +507,16 @@ public function searchWithHttpInfo($q = null, $limit = null, $offset = null, $la try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -670,8 +677,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -679,8 +687,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -920,7 +928,7 @@ public function searchRequest($q = null, $limit = null, $offset = null, $languag } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/SourceCode/Api/ContentApi.php b/codegen/Cms/SourceCode/Api/ContentApi.php index b164e3623..b6de7e2f2 100644 --- a/codegen/Cms/SourceCode/Api/ContentApi.php +++ b/codegen/Cms/SourceCode/Api/ContentApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\SourceCode\ApiException; @@ -174,13 +174,16 @@ public function archiveWithHttpInfo($environment, $path, string $contentType = s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -256,8 +259,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -265,8 +269,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -354,7 +358,7 @@ public function archiveRequest($environment, $path, string $contentType = self:: } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -432,13 +436,16 @@ public function createWithHttpInfo($environment, $path, $file = null, string $co try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -573,8 +580,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -582,8 +590,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -684,7 +692,7 @@ public function createRequest($environment, $path, $file = null, string $content } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -760,13 +768,16 @@ public function createOrUpdateWithHttpInfo($environment, $path, $file = null, st try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -899,8 +910,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -908,8 +920,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1009,7 +1021,7 @@ public function createOrUpdateRequest($environment, $path, $file = null, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1083,13 +1095,16 @@ public function downloadWithHttpInfo($environment, $path, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1220,8 +1235,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1229,8 +1245,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1318,7 +1334,7 @@ public function downloadRequest($environment, $path, string $contentType = self: } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/SourceCode/Api/ExtractApi.php b/codegen/Cms/SourceCode/Api/ExtractApi.php index bbe1377b3..381cc0ef4 100644 --- a/codegen/Cms/SourceCode/Api/ExtractApi.php +++ b/codegen/Cms/SourceCode/Api/ExtractApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\SourceCode\ApiException; @@ -167,13 +167,16 @@ public function doAsyncWithHttpInfo($file_extract_request, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -302,8 +305,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -311,8 +315,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -359,7 +363,7 @@ public function doAsyncRequest($file_extract_request, string $contentType = self if (isset($file_extract_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($file_extract_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($file_extract_request), JSON_THROW_ON_ERROR); } else { $httpBody = $file_extract_request; } @@ -380,7 +384,7 @@ public function doAsyncRequest($file_extract_request, string $contentType = self } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -452,13 +456,16 @@ public function getAsyncStatusWithHttpInfo($task_id, string $contentType = self: try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -587,8 +594,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -596,8 +604,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -666,7 +674,7 @@ public function getAsyncStatusRequest($task_id, string $contentType = self::cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/SourceCode/Api/MetadataApi.php b/codegen/Cms/SourceCode/Api/MetadataApi.php index e2f2847d0..33dd5bc71 100644 --- a/codegen/Cms/SourceCode/Api/MetadataApi.php +++ b/codegen/Cms/SourceCode/Api/MetadataApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\SourceCode\ApiException; @@ -168,13 +168,16 @@ public function getWithHttpInfo($environment, $path, $properties = null, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -307,8 +310,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -316,8 +320,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -416,7 +420,7 @@ public function getRequest($environment, $path, $properties = null, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/SourceCode/Api/ValidationApi.php b/codegen/Cms/SourceCode/Api/ValidationApi.php index 66dbbce06..f63a08035 100644 --- a/codegen/Cms/SourceCode/Api/ValidationApi.php +++ b/codegen/Cms/SourceCode/Api/ValidationApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\SourceCode\ApiException; @@ -168,13 +168,16 @@ public function doValidateWithHttpInfo($environment, $path, $file = null, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -293,8 +296,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -302,8 +306,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -406,7 +410,7 @@ public function doValidateRequest($environment, $path, $file = null, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Cms/UrlRedirects/Api/RedirectsApi.php b/codegen/Cms/UrlRedirects/Api/RedirectsApi.php index b066f5220..11ad7124d 100644 --- a/codegen/Cms/UrlRedirects/Api/RedirectsApi.php +++ b/codegen/Cms/UrlRedirects/Api/RedirectsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Cms\UrlRedirects\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($url_redirect_id, string $contentType = self try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -255,8 +258,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -264,8 +268,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -334,7 +338,7 @@ public function archiveRequest($url_redirect_id, string $contentType = self::con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -406,13 +410,16 @@ public function createWithHttpInfo($url_mapping_create_request_body, string $con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -541,8 +548,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -550,8 +558,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -598,7 +606,7 @@ public function createRequest($url_mapping_create_request_body, string $contentT if (isset($url_mapping_create_request_body)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($url_mapping_create_request_body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($url_mapping_create_request_body), JSON_THROW_ON_ERROR); } else { $httpBody = $url_mapping_create_request_body; } @@ -619,7 +627,7 @@ public function createRequest($url_mapping_create_request_body, string $contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -691,13 +699,16 @@ public function getByIdWithHttpInfo($url_redirect_id, string $contentType = self try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -826,8 +837,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -835,8 +847,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -905,7 +917,7 @@ public function getByIdRequest($url_redirect_id, string $contentType = self::con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -995,13 +1007,16 @@ public function getPageWithHttpInfo($created_at = null, $created_after = null, $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1148,8 +1163,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1157,8 +1173,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1321,7 +1337,7 @@ public function getPageRequest($created_at = null, $created_after = null, $creat } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1395,13 +1411,16 @@ public function updateWithHttpInfo($url_redirect_id, $url_mapping, string $conte try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1532,8 +1551,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1541,8 +1561,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1605,7 +1625,7 @@ public function updateRequest($url_redirect_id, $url_mapping, string $contentTyp if (isset($url_mapping)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($url_mapping)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($url_mapping), JSON_THROW_ON_ERROR); } else { $httpBody = $url_mapping; } @@ -1626,7 +1646,7 @@ public function updateRequest($url_redirect_id, $url_mapping, string $contentTyp } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/CommunicationPreferences/Api/DefinitionsApi.php b/codegen/CommunicationPreferences/Api/DefinitionsApi.php index 412f1c139..383538b9a 100644 --- a/codegen/CommunicationPreferences/Api/DefinitionsApi.php +++ b/codegen/CommunicationPreferences/Api/DefinitionsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\CommunicationPreferences\ApiException; @@ -162,13 +162,16 @@ public function getPageWithHttpInfo(string $contentType = self::contentTypes['ge try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -295,8 +298,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -304,8 +308,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -358,7 +362,7 @@ public function getPageRequest(string $contentType = self::contentTypes['getPage } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/CommunicationPreferences/Api/StatusApi.php b/codegen/CommunicationPreferences/Api/StatusApi.php index cd67ca6ca..1ef67b1a5 100644 --- a/codegen/CommunicationPreferences/Api/StatusApi.php +++ b/codegen/CommunicationPreferences/Api/StatusApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\CommunicationPreferences\ApiException; @@ -170,13 +170,16 @@ public function getEmailStatusWithHttpInfo($email_address, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -305,8 +308,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -314,8 +318,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -384,7 +388,7 @@ public function getEmailStatusRequest($email_address, string $contentType = self } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -456,13 +460,16 @@ public function subscribeWithHttpInfo($public_update_subscription_status_request try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -591,8 +598,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -600,8 +608,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -648,7 +656,7 @@ public function subscribeRequest($public_update_subscription_status_request, str if (isset($public_update_subscription_status_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_update_subscription_status_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_update_subscription_status_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_update_subscription_status_request; } @@ -669,7 +677,7 @@ public function subscribeRequest($public_update_subscription_status_request, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -741,13 +749,16 @@ public function unsubscribeWithHttpInfo($public_update_subscription_status_reque try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -876,8 +887,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -885,8 +897,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -933,7 +945,7 @@ public function unsubscribeRequest($public_update_subscription_status_request, s if (isset($public_update_subscription_status_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_update_subscription_status_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_update_subscription_status_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_update_subscription_status_request; } @@ -954,7 +966,7 @@ public function unsubscribeRequest($public_update_subscription_status_request, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Conversations/VisitorIdentification/Api/GenerateApi.php b/codegen/Conversations/VisitorIdentification/Api/GenerateApi.php index b37242d91..6b132c4be 100644 --- a/codegen/Conversations/VisitorIdentification/Api/GenerateApi.php +++ b/codegen/Conversations/VisitorIdentification/Api/GenerateApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Conversations\VisitorIdentification\ApiException; @@ -164,13 +164,16 @@ public function generateTokenWithHttpInfo($identification_token_generation_reque try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -299,8 +302,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -308,8 +312,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -356,7 +360,7 @@ public function generateTokenRequest($identification_token_generation_request, s if (isset($identification_token_generation_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($identification_token_generation_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($identification_token_generation_request), JSON_THROW_ON_ERROR); } else { $httpBody = $identification_token_generation_request; } @@ -377,7 +381,7 @@ public function generateTokenRequest($identification_token_generation_request, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Associations/Schema/Api/TypesApi.php b/codegen/Crm/Associations/Schema/Api/TypesApi.php index cb53ea575..b705dfc6e 100644 --- a/codegen/Crm/Associations/Schema/Api/TypesApi.php +++ b/codegen/Crm/Associations/Schema/Api/TypesApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Associations\Schema\ApiException; @@ -166,13 +166,16 @@ public function getAllWithHttpInfo($from_object_type, $to_object_type, string $c try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -303,8 +306,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -312,8 +316,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -398,7 +402,7 @@ public function getAllRequest($from_object_type, $to_object_type, string $conten } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Associations/V4/Schema/Api/DefinitionConfigurationsApi.php b/codegen/Crm/Associations/V4/Schema/Api/DefinitionConfigurationsApi.php index 588a0e134..357efcedc 100644 --- a/codegen/Crm/Associations/V4/Schema/Api/DefinitionConfigurationsApi.php +++ b/codegen/Crm/Associations/V4/Schema/Api/DefinitionConfigurationsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Associations\V4\Schema\ApiException; @@ -180,13 +180,16 @@ public function batchCreateWithHttpInfo($from_object_type, $to_object_type, $bat try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -319,8 +322,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -328,8 +332,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -408,7 +412,7 @@ public function batchCreateRequest($from_object_type, $to_object_type, $batch_in if (isset($batch_input_public_association_definition_configuration_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_definition_configuration_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_definition_configuration_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association_definition_configuration_create_request; } @@ -429,7 +433,7 @@ public function batchCreateRequest($from_object_type, $to_object_type, $batch_in } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -505,13 +509,16 @@ public function batchRemoveWithHttpInfo($from_object_type, $to_object_type, $bat try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -644,8 +651,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -653,8 +661,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -733,7 +741,7 @@ public function batchRemoveRequest($from_object_type, $to_object_type, $batch_in if (isset($batch_input_public_association_spec)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_spec)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_spec), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association_spec; } @@ -754,7 +762,7 @@ public function batchRemoveRequest($from_object_type, $to_object_type, $batch_in } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -830,13 +838,16 @@ public function batchUpdateWithHttpInfo($from_object_type, $to_object_type, $bat try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -969,8 +980,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -978,8 +990,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1058,7 +1070,7 @@ public function batchUpdateRequest($from_object_type, $to_object_type, $batch_in if (isset($batch_input_public_association_definition_configuration_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_definition_configuration_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_definition_configuration_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association_definition_configuration_update_request; } @@ -1079,7 +1091,7 @@ public function batchUpdateRequest($from_object_type, $to_object_type, $batch_in } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1149,13 +1161,16 @@ public function getPageWithHttpInfo(string $contentType = self::contentTypes['ge try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1282,8 +1297,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1291,8 +1307,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1345,7 +1361,7 @@ public function getPageRequest(string $contentType = self::contentTypes['getPage } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1419,13 +1435,16 @@ public function getPageBetweenTwoObjectTypesWithHttpInfo($from_object_type, $to_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1556,8 +1575,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1565,8 +1585,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1651,7 +1671,7 @@ public function getPageBetweenTwoObjectTypesRequest($from_object_type, $to_objec } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Associations/V4/Schema/Api/DefinitionsApi.php b/codegen/Crm/Associations/V4/Schema/Api/DefinitionsApi.php index 90447074d..5e475573e 100644 --- a/codegen/Crm/Associations/V4/Schema/Api/DefinitionsApi.php +++ b/codegen/Crm/Associations/V4/Schema/Api/DefinitionsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Associations\V4\Schema\ApiException; @@ -177,13 +177,16 @@ public function createWithHttpInfo($from_object_type, $to_object_type, $public_a try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -316,8 +319,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -325,8 +329,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -405,7 +409,7 @@ public function createRequest($from_object_type, $to_object_type, $public_associ if (isset($public_association_definition_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_association_definition_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_association_definition_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_association_definition_create_request; } @@ -426,7 +430,7 @@ public function createRequest($from_object_type, $to_object_type, $public_associ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -500,13 +504,16 @@ public function getPageWithHttpInfo($from_object_type, $to_object_type, string $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -637,8 +644,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -646,8 +654,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -732,7 +740,7 @@ public function getPageRequest($from_object_type, $to_object_type, string $conte } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -807,13 +815,16 @@ public function removeWithHttpInfo($association_type_id, $from_object_type, $to_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -891,8 +902,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -900,8 +912,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1002,7 +1014,7 @@ public function removeRequest($association_type_id, $from_object_type, $to_objec } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1077,13 +1089,16 @@ public function updateWithHttpInfo($from_object_type, $to_object_type, $public_a try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1161,8 +1176,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1170,8 +1186,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1250,7 +1266,7 @@ public function updateRequest($from_object_type, $to_object_type, $public_associ if (isset($public_association_definition_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_association_definition_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_association_definition_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_association_definition_update_request; } @@ -1271,7 +1287,7 @@ public function updateRequest($from_object_type, $to_object_type, $public_associ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Exports/Api/PublicExportsApi.php b/codegen/Crm/Exports/Api/PublicExportsApi.php index f34f8246e..72338a9db 100644 --- a/codegen/Crm/Exports/Api/PublicExportsApi.php +++ b/codegen/Crm/Exports/Api/PublicExportsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Exports\ApiException; @@ -170,13 +170,16 @@ public function getByIdWithHttpInfo($export_id, string $contentType = self::cont try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -305,8 +308,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -314,8 +318,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -384,7 +388,7 @@ public function getByIdRequest($export_id, string $contentType = self::contentTy } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -456,13 +460,16 @@ public function getStatusWithHttpInfo($task_id, string $contentType = self::cont try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -591,8 +598,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -600,8 +608,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -670,7 +678,7 @@ public function getStatusRequest($task_id, string $contentType = self::contentTy } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -742,13 +750,16 @@ public function startWithHttpInfo($public_export_request, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -877,8 +888,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -886,8 +898,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -934,7 +946,7 @@ public function startRequest($public_export_request, string $contentType = self: if (isset($public_export_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_export_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_export_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_export_request; } @@ -955,7 +967,7 @@ public function startRequest($public_export_request, string $contentType = self: } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Extensions/Calling/Api/ChannelConnectionSettingsApi.php b/codegen/Crm/Extensions/Calling/Api/ChannelConnectionSettingsApi.php index 694651829..3bf7bba14 100644 --- a/codegen/Crm/Extensions/Calling/Api/ChannelConnectionSettingsApi.php +++ b/codegen/Crm/Extensions/Calling/Api/ChannelConnectionSettingsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Extensions\Calling\ApiException; @@ -175,13 +175,16 @@ public function createWithHttpInfo($app_id, $channel_connection_settings_request try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -312,8 +315,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -321,8 +325,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -385,7 +389,7 @@ public function createRequest($app_id, $channel_connection_settings_request, str if (isset($channel_connection_settings_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($channel_connection_settings_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($channel_connection_settings_request), JSON_THROW_ON_ERROR); } else { $httpBody = $channel_connection_settings_request; } @@ -406,7 +410,7 @@ public function createRequest($app_id, $channel_connection_settings_request, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -479,13 +483,16 @@ public function getWithHttpInfo($app_id, string $contentType = self::contentType try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -614,8 +621,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -623,8 +631,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -693,7 +701,7 @@ public function getRequest($app_id, string $contentType = self::contentTypes['ge } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -765,13 +773,16 @@ public function removeWithHttpInfo($app_id, string $contentType = self::contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -845,8 +856,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -854,8 +866,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -924,7 +936,7 @@ public function removeRequest($app_id, string $contentType = self::contentTypes[ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -999,13 +1011,16 @@ public function updateWithHttpInfo($app_id, $channel_connection_settings_patch_r try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1136,8 +1151,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1145,8 +1161,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1209,7 +1225,7 @@ public function updateRequest($app_id, $channel_connection_settings_patch_reques if (isset($channel_connection_settings_patch_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($channel_connection_settings_patch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($channel_connection_settings_patch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $channel_connection_settings_patch_request; } @@ -1230,7 +1246,7 @@ public function updateRequest($app_id, $channel_connection_settings_patch_reques } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Extensions/Calling/Api/RecordingSettingsApi.php b/codegen/Crm/Extensions/Calling/Api/RecordingSettingsApi.php index f71ae459b..3c0be333e 100644 --- a/codegen/Crm/Extensions/Calling/Api/RecordingSettingsApi.php +++ b/codegen/Crm/Extensions/Calling/Api/RecordingSettingsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Extensions\Calling\ApiException; @@ -175,13 +175,16 @@ public function createWithHttpInfo($app_id, $recording_settings_request, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -312,8 +315,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -321,8 +325,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -385,7 +389,7 @@ public function createRequest($app_id, $recording_settings_request, string $cont if (isset($recording_settings_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($recording_settings_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($recording_settings_request), JSON_THROW_ON_ERROR); } else { $httpBody = $recording_settings_request; } @@ -406,7 +410,7 @@ public function createRequest($app_id, $recording_settings_request, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -479,13 +483,16 @@ public function getWithHttpInfo($app_id, string $contentType = self::contentType try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -614,8 +621,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -623,8 +631,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -693,7 +701,7 @@ public function getRequest($app_id, string $contentType = self::contentTypes['ge } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -765,13 +773,16 @@ public function markAsReadyWithHttpInfo($mark_recording_as_ready_request, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -845,8 +856,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -854,8 +866,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -902,7 +914,7 @@ public function markAsReadyRequest($mark_recording_as_ready_request, string $con if (isset($mark_recording_as_ready_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($mark_recording_as_ready_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($mark_recording_as_ready_request), JSON_THROW_ON_ERROR); } else { $httpBody = $mark_recording_as_ready_request; } @@ -923,7 +935,7 @@ public function markAsReadyRequest($mark_recording_as_ready_request, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -997,13 +1009,16 @@ public function updateWithHttpInfo($app_id, $recording_settings_patch_request, s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1134,8 +1149,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1143,8 +1159,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1207,7 +1223,7 @@ public function updateRequest($app_id, $recording_settings_patch_request, string if (isset($recording_settings_patch_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($recording_settings_patch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($recording_settings_patch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $recording_settings_patch_request; } @@ -1228,7 +1244,7 @@ public function updateRequest($app_id, $recording_settings_patch_request, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Extensions/Calling/Api/SettingsApi.php b/codegen/Crm/Extensions/Calling/Api/SettingsApi.php index 43be6801e..1c9a041c2 100644 --- a/codegen/Crm/Extensions/Calling/Api/SettingsApi.php +++ b/codegen/Crm/Extensions/Calling/Api/SettingsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Extensions\Calling\ApiException; @@ -175,13 +175,16 @@ public function createWithHttpInfo($app_id, $settings_request, string $contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -312,8 +315,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -321,8 +325,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -385,7 +389,7 @@ public function createRequest($app_id, $settings_request, string $contentType = if (isset($settings_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($settings_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($settings_request), JSON_THROW_ON_ERROR); } else { $httpBody = $settings_request; } @@ -406,7 +410,7 @@ public function createRequest($app_id, $settings_request, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -479,13 +483,16 @@ public function getWithHttpInfo($app_id, string $contentType = self::contentType try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -614,8 +621,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -623,8 +631,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -693,7 +701,7 @@ public function getRequest($app_id, string $contentType = self::contentTypes['ge } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -765,13 +773,16 @@ public function removeWithHttpInfo($app_id, string $contentType = self::contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -845,8 +856,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -854,8 +866,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -924,7 +936,7 @@ public function removeRequest($app_id, string $contentType = self::contentTypes[ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -999,13 +1011,16 @@ public function updateWithHttpInfo($app_id, $settings_patch_request, string $con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1136,8 +1151,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1145,8 +1161,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1209,7 +1225,7 @@ public function updateRequest($app_id, $settings_patch_request, string $contentT if (isset($settings_patch_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($settings_patch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($settings_patch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $settings_patch_request; } @@ -1230,7 +1246,7 @@ public function updateRequest($app_id, $settings_patch_request, string $contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Extensions/Cards/Api/CardsApi.php b/codegen/Crm/Extensions/Cards/Api/CardsApi.php index 927fd50d3..e36293e60 100644 --- a/codegen/Crm/Extensions/Cards/Api/CardsApi.php +++ b/codegen/Crm/Extensions/Cards/Api/CardsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Extensions\Cards\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($card_id, $app_id, string $contentType = sel try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -259,8 +262,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -268,8 +272,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -354,7 +358,7 @@ public function archiveRequest($card_id, $app_id, string $contentType = self::co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -429,13 +433,16 @@ public function createWithHttpInfo($app_id, $card_create_request, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -566,8 +573,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -575,8 +583,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -639,7 +647,7 @@ public function createRequest($app_id, $card_create_request, string $contentType if (isset($card_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($card_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($card_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $card_create_request; } @@ -660,7 +668,7 @@ public function createRequest($app_id, $card_create_request, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -733,13 +741,16 @@ public function getAllWithHttpInfo($app_id, string $contentType = self::contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -868,8 +879,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -877,8 +889,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -947,7 +959,7 @@ public function getAllRequest($app_id, string $contentType = self::contentTypes[ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1022,13 +1034,16 @@ public function getByIdWithHttpInfo($card_id, $app_id, string $contentType = sel try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1159,8 +1174,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1168,8 +1184,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1254,7 +1270,7 @@ public function getByIdRequest($card_id, $app_id, string $contentType = self::co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1331,13 +1347,16 @@ public function updateWithHttpInfo($card_id, $app_id, $card_patch_request, strin try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1470,8 +1489,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1479,8 +1499,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1559,7 +1579,7 @@ public function updateRequest($card_id, $app_id, $card_patch_request, string $co if (isset($card_patch_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($card_patch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($card_patch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $card_patch_request; } @@ -1580,7 +1600,7 @@ public function updateRequest($card_id, $app_id, $card_patch_request, string $co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Extensions/Cards/Api/SampleResponseApi.php b/codegen/Crm/Extensions/Cards/Api/SampleResponseApi.php index e16513f5d..18fee3a9b 100644 --- a/codegen/Crm/Extensions/Cards/Api/SampleResponseApi.php +++ b/codegen/Crm/Extensions/Cards/Api/SampleResponseApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Extensions\Cards\ApiException; @@ -162,13 +162,16 @@ public function getCardsSampleResponseWithHttpInfo(string $contentType = self::c try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -295,8 +298,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -304,8 +308,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -358,7 +362,7 @@ public function getCardsSampleResponseRequest(string $contentType = self::conten } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Extensions/Videoconferencing/Api/SettingsApi.php b/codegen/Crm/Extensions/Videoconferencing/Api/SettingsApi.php index 06efc9e5e..6b7f8d6cd 100644 --- a/codegen/Crm/Extensions/Videoconferencing/Api/SettingsApi.php +++ b/codegen/Crm/Extensions/Videoconferencing/Api/SettingsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Extensions\Videoconferencing\ApiException; @@ -169,13 +169,16 @@ public function archiveWithHttpInfo($app_id, string $contentType = self::content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -249,8 +252,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -258,8 +262,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -328,7 +332,7 @@ public function archiveRequest($app_id, string $contentType = self::contentTypes } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -401,13 +405,16 @@ public function getByIdWithHttpInfo($app_id, string $contentType = self::content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -536,8 +543,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -545,8 +553,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -615,7 +623,7 @@ public function getByIdRequest($app_id, string $contentType = self::contentTypes } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -690,13 +698,16 @@ public function replaceWithHttpInfo($app_id, $external_settings, string $content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -827,8 +838,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -836,8 +848,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -900,7 +912,7 @@ public function replaceRequest($app_id, $external_settings, string $contentType if (isset($external_settings)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($external_settings)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($external_settings), JSON_THROW_ON_ERROR); } else { $httpBody = $external_settings; } @@ -921,7 +933,7 @@ public function replaceRequest($app_id, $external_settings, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Imports/Api/CoreApi.php b/codegen/Crm/Imports/Api/CoreApi.php index 7b6a6198c..92cc1c2d6 100644 --- a/codegen/Crm/Imports/Api/CoreApi.php +++ b/codegen/Crm/Imports/Api/CoreApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Imports\ApiException; @@ -173,13 +173,16 @@ public function cancelWithHttpInfo($import_id, string $contentType = self::conte try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -308,8 +311,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -317,8 +321,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -387,7 +391,7 @@ public function cancelRequest($import_id, string $contentType = self::contentTyp } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -461,13 +465,16 @@ public function createWithHttpInfo($files = null, $import_request = null, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -598,8 +605,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -607,8 +615,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -676,7 +684,7 @@ public function createRequest($files = null, $import_request = null, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -748,13 +756,16 @@ public function getByIdWithHttpInfo($import_id, string $contentType = self::cont try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -883,8 +894,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -892,8 +904,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -962,7 +974,7 @@ public function getByIdRequest($import_id, string $contentType = self::contentTy } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1038,13 +1050,16 @@ public function getPageWithHttpInfo($after = null, $before = null, $limit = null try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1177,8 +1192,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1186,8 +1202,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1273,7 +1289,7 @@ public function getPageRequest($after = null, $before = null, $limit = null, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Imports/Api/PublicImportsApi.php b/codegen/Crm/Imports/Api/PublicImportsApi.php index 3fd1f4891..894fbcb69 100644 --- a/codegen/Crm/Imports/Api/PublicImportsApi.php +++ b/codegen/Crm/Imports/Api/PublicImportsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Imports\ApiException; @@ -172,13 +172,16 @@ public function getErrorsWithHttpInfo($import_id, $after = null, $limit = null, try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -315,8 +318,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -324,8 +328,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -438,7 +442,7 @@ public function getErrorsRequest($import_id, $after = null, $limit = null, $incl } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Lists/Api/IDMappingApi.php b/codegen/Crm/Lists/Api/IDMappingApi.php index bf6fcbd59..a5e2f9415 100644 --- a/codegen/Crm/Lists/Api/IDMappingApi.php +++ b/codegen/Crm/Lists/Api/IDMappingApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Lists\ApiException; @@ -167,13 +167,16 @@ public function translateLegacyListIdToListIdWithHttpInfo($legacy_list_id = null try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -302,8 +305,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -311,8 +315,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -376,7 +380,7 @@ public function translateLegacyListIdToListIdRequest($legacy_list_id = null, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -448,13 +452,16 @@ public function translateLegacyListIdToListIdBatchWithHttpInfo($request_body, st try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -583,8 +590,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -592,8 +600,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -640,7 +648,7 @@ public function translateLegacyListIdToListIdBatchRequest($request_body, string if (isset($request_body)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($request_body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($request_body), JSON_THROW_ON_ERROR); } else { $httpBody = $request_body; } @@ -661,7 +669,7 @@ public function translateLegacyListIdToListIdBatchRequest($request_body, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Lists/Api/JoinOrderApi.php b/codegen/Crm/Lists/Api/JoinOrderApi.php index 4f66d9691..f9f214442 100644 --- a/codegen/Crm/Lists/Api/JoinOrderApi.php +++ b/codegen/Crm/Lists/Api/JoinOrderApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Lists\ApiException; @@ -170,13 +170,16 @@ public function getPageOrderedByAddedToListDateWithHttpInfo($list_id, $after = n try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -311,8 +314,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -320,8 +324,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -423,7 +427,7 @@ public function getPageOrderedByAddedToListDateRequest($list_id, $after = null, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Lists/Api/ListManagementApi.php b/codegen/Crm/Lists/Api/ListManagementApi.php index 6c2e1a4d8..6a2ec9c4f 100644 --- a/codegen/Crm/Lists/Api/ListManagementApi.php +++ b/codegen/Crm/Lists/Api/ListManagementApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Lists\ApiException; @@ -187,13 +187,16 @@ public function cancelConversionWithHttpInfo($list_id, string $contentType = sel try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -267,8 +270,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -276,8 +280,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -346,7 +350,7 @@ public function cancelConversionRequest($list_id, string $contentType = self::co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -418,13 +422,16 @@ public function createFolderWithHttpInfo($list_folder_create_request, string $co try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -553,8 +560,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -562,8 +570,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -610,7 +618,7 @@ public function createFolderRequest($list_folder_create_request, string $content if (isset($list_folder_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($list_folder_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($list_folder_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $list_folder_create_request; } @@ -631,7 +639,7 @@ public function createFolderRequest($list_folder_create_request, string $content } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -703,13 +711,16 @@ public function getConversionDetailsWithHttpInfo($list_id, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -838,8 +849,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -847,8 +859,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -917,7 +929,7 @@ public function getConversionDetailsRequest($list_id, string $contentType = self } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -989,13 +1001,16 @@ public function getFolderWithHttpInfo($folder_id = '0', string $contentType = se try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1124,8 +1139,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1133,8 +1149,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1198,7 +1214,7 @@ public function getFolderRequest($folder_id = '0', string $contentType = self::c } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1272,13 +1288,16 @@ public function moveFolderWithHttpInfo($folder_id, $new_parent_folder_id, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1409,8 +1428,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1418,8 +1438,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1504,7 +1524,7 @@ public function moveFolderRequest($folder_id, $new_parent_folder_id, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1575,13 +1595,16 @@ public function moveListToFolderWithHttpInfo($list_move_request, string $content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1655,8 +1678,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1664,8 +1688,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1712,7 +1736,7 @@ public function moveListToFolderRequest($list_move_request, string $contentType if (isset($list_move_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($list_move_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($list_move_request), JSON_THROW_ON_ERROR); } else { $httpBody = $list_move_request; } @@ -1733,7 +1757,7 @@ public function moveListToFolderRequest($list_move_request, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1804,13 +1828,16 @@ public function removeFolderWithHttpInfo($folder_id, string $contentType = self: try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1884,8 +1911,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1893,8 +1921,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1963,7 +1991,7 @@ public function removeFolderRequest($folder_id, string $contentType = self::cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2037,13 +2065,16 @@ public function renameFolderWithHttpInfo($folder_id, $new_folder_name = null, st try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2174,8 +2205,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2183,8 +2215,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2264,7 +2296,7 @@ public function renameFolderRequest($folder_id, $new_folder_name = null, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2338,13 +2370,16 @@ public function scheduleOrUpdateConversionWithHttpInfo($list_id, $public_list_co try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2475,8 +2510,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2484,8 +2520,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2548,7 +2584,7 @@ public function scheduleOrUpdateConversionRequest($list_id, $public_list_convers if (isset($public_list_conversion_time)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_list_conversion_time)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_list_conversion_time), JSON_THROW_ON_ERROR); } else { $httpBody = $public_list_conversion_time; } @@ -2569,7 +2605,7 @@ public function scheduleOrUpdateConversionRequest($list_id, $public_list_convers } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Lists/Api/ListsApi.php b/codegen/Crm/Lists/Api/ListsApi.php index 0e5bc1c0a..d568362e1 100644 --- a/codegen/Crm/Lists/Api/ListsApi.php +++ b/codegen/Crm/Lists/Api/ListsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Lists\ApiException; @@ -188,13 +188,16 @@ public function createWithHttpInfo($list_create_request, string $contentType = s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -323,8 +326,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -332,8 +336,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -380,7 +384,7 @@ public function createRequest($list_create_request, string $contentType = self:: if (isset($list_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($list_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($list_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $list_create_request; } @@ -401,7 +405,7 @@ public function createRequest($list_create_request, string $contentType = self:: } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -473,13 +477,16 @@ public function doSearchWithHttpInfo($list_search_request, string $contentType = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -608,8 +615,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -617,8 +625,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -665,7 +673,7 @@ public function doSearchRequest($list_search_request, string $contentType = self if (isset($list_search_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($list_search_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($list_search_request), JSON_THROW_ON_ERROR); } else { $httpBody = $list_search_request; } @@ -686,7 +694,7 @@ public function doSearchRequest($list_search_request, string $contentType = self } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -760,13 +768,16 @@ public function getAllWithHttpInfo($list_ids = null, $include_filters = false, s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -897,8 +908,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -906,8 +918,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -982,7 +994,7 @@ public function getAllRequest($list_ids = null, $include_filters = false, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1056,13 +1068,16 @@ public function getByIdWithHttpInfo($list_id, $include_filters = false, string $ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1193,8 +1208,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1202,8 +1218,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1283,7 +1299,7 @@ public function getByIdRequest($list_id, $include_filters = false, string $conte } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1359,13 +1375,16 @@ public function getByNameWithHttpInfo($list_name, $object_type_id, $include_filt try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1498,8 +1517,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1507,8 +1527,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1604,7 +1624,7 @@ public function getByNameRequest($list_name, $object_type_id, $include_filters = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1675,13 +1695,16 @@ public function removeWithHttpInfo($list_id, string $contentType = self::content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1755,8 +1778,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1764,8 +1788,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1834,7 +1858,7 @@ public function removeRequest($list_id, string $contentType = self::contentTypes } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1905,13 +1929,16 @@ public function restoreWithHttpInfo($list_id, string $contentType = self::conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1985,8 +2012,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1994,8 +2022,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2064,7 +2092,7 @@ public function restoreRequest($list_id, string $contentType = self::contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2140,13 +2168,16 @@ public function updateListFiltersWithHttpInfo($list_id, $list_filter_update_requ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2279,8 +2310,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2288,8 +2320,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2363,7 +2395,7 @@ public function updateListFiltersRequest($list_id, $list_filter_update_request, if (isset($list_filter_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($list_filter_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($list_filter_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $list_filter_update_request; } @@ -2384,7 +2416,7 @@ public function updateListFiltersRequest($list_id, $list_filter_update_request, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -2460,13 +2492,16 @@ public function updateNameWithHttpInfo($list_id, $list_name = null, $include_fil try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2599,8 +2634,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2608,8 +2644,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2700,7 +2736,7 @@ public function updateNameRequest($list_id, $list_name = null, $include_filters } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Lists/Api/MembershipsApi.php b/codegen/Crm/Lists/Api/MembershipsApi.php index cac0cb206..7b817b0b9 100644 --- a/codegen/Crm/Lists/Api/MembershipsApi.php +++ b/codegen/Crm/Lists/Api/MembershipsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Lists\ApiException; @@ -184,13 +184,16 @@ public function addWithHttpInfo($list_id, $request_body, string $contentType = s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -321,8 +324,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -330,8 +334,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -394,7 +398,7 @@ public function addRequest($list_id, $request_body, string $contentType = self:: if (isset($request_body)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($request_body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($request_body), JSON_THROW_ON_ERROR); } else { $httpBody = $request_body; } @@ -415,7 +419,7 @@ public function addRequest($list_id, $request_body, string $contentType = self:: } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -488,13 +492,16 @@ public function addAllFromListWithHttpInfo($list_id, $source_list_id, string $co try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -570,8 +577,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -579,8 +587,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -665,7 +673,7 @@ public function addAllFromListRequest($list_id, $source_list_id, string $content } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -739,13 +747,16 @@ public function addAndRemoveWithHttpInfo($list_id, $membership_change_request, s try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -876,8 +887,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -885,8 +897,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -949,7 +961,7 @@ public function addAndRemoveRequest($list_id, $membership_change_request, string if (isset($membership_change_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($membership_change_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($membership_change_request), JSON_THROW_ON_ERROR); } else { $httpBody = $membership_change_request; } @@ -970,7 +982,7 @@ public function addAndRemoveRequest($list_id, $membership_change_request, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1044,13 +1056,16 @@ public function getListsWithHttpInfo($object_type_id, $record_id, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1181,8 +1196,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1190,8 +1206,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1276,7 +1292,7 @@ public function getListsRequest($object_type_id, $record_id, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1354,13 +1370,16 @@ public function getPageWithHttpInfo($list_id, $after = null, $before = null, $li try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1495,8 +1514,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1504,8 +1524,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1607,7 +1627,7 @@ public function getPageRequest($list_id, $after = null, $before = null, $limit = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1681,13 +1701,16 @@ public function removeWithHttpInfo($list_id, $request_body, string $contentType try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1818,8 +1841,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1827,8 +1851,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1891,7 +1915,7 @@ public function removeRequest($list_id, $request_body, string $contentType = sel if (isset($request_body)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($request_body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($request_body), JSON_THROW_ON_ERROR); } else { $httpBody = $request_body; } @@ -1912,7 +1936,7 @@ public function removeRequest($list_id, $request_body, string $contentType = sel } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1983,13 +2007,16 @@ public function removeAllWithHttpInfo($list_id, string $contentType = self::cont try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -2063,8 +2090,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -2072,8 +2100,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2142,7 +2170,7 @@ public function removeAllRequest($list_id, string $contentType = self::contentTy } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Objects/Api/BasicApi.php b/codegen/Crm/Objects/Api/BasicApi.php index fb2e22d5c..d3c8e9ba0 100644 --- a/codegen/Crm/Objects/Api/BasicApi.php +++ b/codegen/Crm/Objects/Api/BasicApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Objects\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($object_type, $object_id, string $contentTyp try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -259,8 +262,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -268,8 +272,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -354,7 +358,7 @@ public function archiveRequest($object_type, $object_id, string $contentType = s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -428,13 +432,16 @@ public function createWithHttpInfo($object_type, $simple_public_object_input_for try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -565,8 +572,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -574,8 +582,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -638,7 +646,7 @@ public function createRequest($object_type, $simple_public_object_input_for_crea if (isset($simple_public_object_input_for_create)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($simple_public_object_input_for_create)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($simple_public_object_input_for_create), JSON_THROW_ON_ERROR); } else { $httpBody = $simple_public_object_input_for_create; } @@ -659,7 +667,7 @@ public function createRequest($object_type, $simple_public_object_input_for_crea } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -743,13 +751,16 @@ public function getByIdWithHttpInfo($object_type, $object_id, $properties = null try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -890,8 +901,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -899,8 +911,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1040,7 +1052,7 @@ public function getByIdRequest($object_type, $object_id, $properties = null, $pr } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1124,13 +1136,16 @@ public function getPageWithHttpInfo($object_type, $limit = 10, $after = null, $p try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1271,8 +1286,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1280,8 +1296,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1416,7 +1432,7 @@ public function getPageRequest($object_type, $limit = 10, $after = null, $proper } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1494,13 +1510,16 @@ public function updateWithHttpInfo($object_id, $object_type, $simple_public_obje try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1635,8 +1654,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1644,8 +1664,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1735,7 +1755,7 @@ public function updateRequest($object_id, $object_type, $simple_public_object_in if (isset($simple_public_object_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($simple_public_object_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($simple_public_object_input), JSON_THROW_ON_ERROR); } else { $httpBody = $simple_public_object_input; } @@ -1756,7 +1776,7 @@ public function updateRequest($object_id, $object_type, $simple_public_object_in } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Objects/Api/BatchApi.php b/codegen/Crm/Objects/Api/BatchApi.php index 2102d50b8..27066ab1b 100644 --- a/codegen/Crm/Objects/Api/BatchApi.php +++ b/codegen/Crm/Objects/Api/BatchApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Objects\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($object_type, $batch_input_simple_public_obj try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -259,8 +262,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -268,8 +272,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -332,7 +336,7 @@ public function archiveRequest($object_type, $batch_input_simple_public_object_i if (isset($batch_input_simple_public_object_id)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_id)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_id), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_simple_public_object_id; } @@ -353,7 +357,7 @@ public function archiveRequest($object_type, $batch_input_simple_public_object_i } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -427,13 +431,16 @@ public function createWithHttpInfo($object_type, $batch_input_simple_public_obje try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -578,8 +585,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -587,8 +595,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -651,7 +659,7 @@ public function createRequest($object_type, $batch_input_simple_public_object_ba if (isset($batch_input_simple_public_object_batch_input_for_create)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_batch_input_for_create)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_batch_input_for_create), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_simple_public_object_batch_input_for_create; } @@ -672,7 +680,7 @@ public function createRequest($object_type, $batch_input_simple_public_object_ba } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -748,13 +756,16 @@ public function readWithHttpInfo($object_type, $batch_read_input_simple_public_o try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -901,8 +912,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -910,8 +922,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -985,7 +997,7 @@ public function readRequest($object_type, $batch_read_input_simple_public_object if (isset($batch_read_input_simple_public_object_id)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_read_input_simple_public_object_id)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_read_input_simple_public_object_id), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_read_input_simple_public_object_id; } @@ -1006,7 +1018,7 @@ public function readRequest($object_type, $batch_read_input_simple_public_object } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1080,13 +1092,16 @@ public function updateWithHttpInfo($object_type, $batch_input_simple_public_obje try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1231,8 +1246,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1240,8 +1256,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1304,7 +1320,7 @@ public function updateRequest($object_type, $batch_input_simple_public_object_ba if (isset($batch_input_simple_public_object_batch_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_batch_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_batch_input), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_simple_public_object_batch_input; } @@ -1325,7 +1341,7 @@ public function updateRequest($object_type, $batch_input_simple_public_object_ba } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1399,13 +1415,16 @@ public function upsertWithHttpInfo($object_type, $batch_input_simple_public_obje try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1550,8 +1569,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1559,8 +1579,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1623,7 +1643,7 @@ public function upsertRequest($object_type, $batch_input_simple_public_object_ba if (isset($batch_input_simple_public_object_batch_input_upsert)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_batch_input_upsert)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_simple_public_object_batch_input_upsert), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_simple_public_object_batch_input_upsert; } @@ -1644,7 +1664,7 @@ public function upsertRequest($object_type, $batch_input_simple_public_object_ba } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Objects/Api/SearchApi.php b/codegen/Crm/Objects/Api/SearchApi.php index a0fd758fd..05103b64d 100644 --- a/codegen/Crm/Objects/Api/SearchApi.php +++ b/codegen/Crm/Objects/Api/SearchApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Objects\ApiException; @@ -162,13 +162,16 @@ public function doSearchWithHttpInfo($object_type, $public_object_search_request try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -295,8 +298,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -304,8 +308,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -368,7 +372,7 @@ public function doSearchRequest($object_type, $public_object_search_request, str if (isset($public_object_search_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($public_object_search_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_object_search_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_object_search_request; } @@ -389,7 +393,7 @@ public function doSearchRequest($object_type, $public_object_search_request, str } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Owners/Api/OwnersApi.php b/codegen/Crm/Owners/Api/OwnersApi.php index 0acf8b41e..13534223d 100644 --- a/codegen/Crm/Owners/Api/OwnersApi.php +++ b/codegen/Crm/Owners/Api/OwnersApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Owners\ApiException; @@ -171,13 +171,16 @@ public function getByIdWithHttpInfo($owner_id, $id_property = 'id', $archived = try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -310,8 +313,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -319,8 +323,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -411,7 +415,7 @@ public function getByIdRequest($owner_id, $id_property = 'id', $archived = false } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -489,13 +493,16 @@ public function getPageWithHttpInfo($email = null, $after = null, $limit = 100, try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -630,8 +637,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -639,8 +647,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -737,7 +745,7 @@ public function getPageRequest($email = null, $after = null, $limit = 100, $arch } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Pipelines/Api/PipelineAuditsApi.php b/codegen/Crm/Pipelines/Api/PipelineAuditsApi.php index 05dea032d..1ff7e6a64 100644 --- a/codegen/Crm/Pipelines/Api/PipelineAuditsApi.php +++ b/codegen/Crm/Pipelines/Api/PipelineAuditsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Pipelines\ApiException; @@ -166,13 +166,16 @@ public function getAuditWithHttpInfo($object_type, $pipeline_id, string $content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -303,8 +306,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -312,8 +316,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -398,7 +402,7 @@ public function getAuditRequest($object_type, $pipeline_id, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Pipelines/Api/PipelineStageAuditsApi.php b/codegen/Crm/Pipelines/Api/PipelineStageAuditsApi.php index 1470855b2..49e95ca9e 100644 --- a/codegen/Crm/Pipelines/Api/PipelineStageAuditsApi.php +++ b/codegen/Crm/Pipelines/Api/PipelineStageAuditsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Pipelines\ApiException; @@ -168,13 +168,16 @@ public function getAuditWithHttpInfo($object_type, $stage_id, $pipeline_id, stri try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -307,8 +310,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -316,8 +320,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -421,7 +425,7 @@ public function getAuditRequest($object_type, $stage_id, $pipeline_id, string $c } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Pipelines/Api/PipelineStagesApi.php b/codegen/Crm/Pipelines/Api/PipelineStagesApi.php index 4676d4de5..c5a44413e 100644 --- a/codegen/Crm/Pipelines/Api/PipelineStagesApi.php +++ b/codegen/Crm/Pipelines/Api/PipelineStagesApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Pipelines\ApiException; @@ -182,13 +182,16 @@ public function archiveWithHttpInfo($object_type, $pipeline_id, $stage_id, strin try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -266,8 +269,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -275,8 +279,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -377,7 +381,7 @@ public function archiveRequest($object_type, $pipeline_id, $stage_id, string $co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -453,13 +457,16 @@ public function createWithHttpInfo($object_type, $pipeline_id, $pipeline_stage_i try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -592,8 +599,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -601,8 +609,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -681,7 +689,7 @@ public function createRequest($object_type, $pipeline_id, $pipeline_stage_input, if (isset($pipeline_stage_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pipeline_stage_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pipeline_stage_input), JSON_THROW_ON_ERROR); } else { $httpBody = $pipeline_stage_input; } @@ -702,7 +710,7 @@ public function createRequest($object_type, $pipeline_id, $pipeline_stage_input, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -776,13 +784,16 @@ public function getAllWithHttpInfo($object_type, $pipeline_id, string $contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -913,8 +924,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -922,8 +934,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1008,7 +1020,7 @@ public function getAllRequest($object_type, $pipeline_id, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1084,13 +1096,16 @@ public function getByIdWithHttpInfo($object_type, $pipeline_id, $stage_id, strin try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1223,8 +1238,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1232,8 +1248,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1334,7 +1350,7 @@ public function getByIdRequest($object_type, $pipeline_id, $stage_id, string $co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1412,13 +1428,16 @@ public function replaceWithHttpInfo($object_type, $pipeline_id, $stage_id, $pipe try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1553,8 +1572,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1562,8 +1582,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1658,7 +1678,7 @@ public function replaceRequest($object_type, $pipeline_id, $stage_id, $pipeline_ if (isset($pipeline_stage_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pipeline_stage_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pipeline_stage_input), JSON_THROW_ON_ERROR); } else { $httpBody = $pipeline_stage_input; } @@ -1679,7 +1699,7 @@ public function replaceRequest($object_type, $pipeline_id, $stage_id, $pipeline_ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1757,13 +1777,16 @@ public function updateWithHttpInfo($object_type, $pipeline_id, $stage_id, $pipel try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1898,8 +1921,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1907,8 +1931,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2003,7 +2027,7 @@ public function updateRequest($object_type, $pipeline_id, $stage_id, $pipeline_s if (isset($pipeline_stage_patch_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pipeline_stage_patch_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pipeline_stage_patch_input), JSON_THROW_ON_ERROR); } else { $httpBody = $pipeline_stage_patch_input; } @@ -2024,7 +2048,7 @@ public function updateRequest($object_type, $pipeline_id, $stage_id, $pipeline_s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Pipelines/Api/PipelinesApi.php b/codegen/Crm/Pipelines/Api/PipelinesApi.php index 48c573530..205c47a33 100644 --- a/codegen/Crm/Pipelines/Api/PipelinesApi.php +++ b/codegen/Crm/Pipelines/Api/PipelinesApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Pipelines\ApiException; @@ -184,13 +184,16 @@ public function archiveWithHttpInfo($object_type, $pipeline_id, $validate_refere try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -270,8 +273,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -279,8 +283,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -387,7 +391,7 @@ public function archiveRequest($object_type, $pipeline_id, $validate_references_ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -461,13 +465,16 @@ public function createWithHttpInfo($object_type, $pipeline_input, string $conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -598,8 +605,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -607,8 +615,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -671,7 +679,7 @@ public function createRequest($object_type, $pipeline_input, string $contentType if (isset($pipeline_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pipeline_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pipeline_input), JSON_THROW_ON_ERROR); } else { $httpBody = $pipeline_input; } @@ -692,7 +700,7 @@ public function createRequest($object_type, $pipeline_input, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -764,13 +772,16 @@ public function getAllWithHttpInfo($object_type, string $contentType = self::con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -899,8 +910,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -908,8 +920,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -978,7 +990,7 @@ public function getAllRequest($object_type, string $contentType = self::contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1052,13 +1064,16 @@ public function getByIdWithHttpInfo($object_type, $pipeline_id, string $contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1189,8 +1204,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1198,8 +1214,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1284,7 +1300,7 @@ public function getByIdRequest($object_type, $pipeline_id, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1364,13 +1380,16 @@ public function replaceWithHttpInfo($object_type, $pipeline_id, $pipeline_input, try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1507,8 +1526,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1516,8 +1536,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1618,7 +1638,7 @@ public function replaceRequest($object_type, $pipeline_id, $pipeline_input, $val if (isset($pipeline_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pipeline_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pipeline_input), JSON_THROW_ON_ERROR); } else { $httpBody = $pipeline_input; } @@ -1639,7 +1659,7 @@ public function replaceRequest($object_type, $pipeline_id, $pipeline_input, $val } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1719,13 +1739,16 @@ public function updateWithHttpInfo($object_type, $pipeline_id, $pipeline_patch_i try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1862,8 +1885,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1871,8 +1895,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1973,7 +1997,7 @@ public function updateRequest($object_type, $pipeline_id, $pipeline_patch_input, if (isset($pipeline_patch_input)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($pipeline_patch_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($pipeline_patch_input), JSON_THROW_ON_ERROR); } else { $httpBody = $pipeline_patch_input; } @@ -1994,7 +2018,7 @@ public function updateRequest($object_type, $pipeline_id, $pipeline_patch_input, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Properties/Api/GroupsApi.php b/codegen/Crm/Properties/Api/GroupsApi.php index 8e4b25525..501b63e7b 100644 --- a/codegen/Crm/Properties/Api/GroupsApi.php +++ b/codegen/Crm/Properties/Api/GroupsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Properties\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($object_type, $group_name, string $contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -259,8 +262,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -268,8 +272,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -354,7 +358,7 @@ public function archiveRequest($object_type, $group_name, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -428,13 +432,16 @@ public function createWithHttpInfo($object_type, $property_group_create, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -565,8 +572,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -574,8 +582,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -638,7 +646,7 @@ public function createRequest($object_type, $property_group_create, string $cont if (isset($property_group_create)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($property_group_create)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($property_group_create), JSON_THROW_ON_ERROR); } else { $httpBody = $property_group_create; } @@ -659,7 +667,7 @@ public function createRequest($object_type, $property_group_create, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -733,13 +741,16 @@ public function getAllWithHttpInfo($object_type, $locale = null, string $content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -870,8 +881,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -879,8 +891,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -960,7 +972,7 @@ public function getAllRequest($object_type, $locale = null, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1036,13 +1048,16 @@ public function getByNameWithHttpInfo($object_type, $group_name, $locale = null, try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1175,8 +1190,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1184,8 +1200,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1281,7 +1297,7 @@ public function getByNameRequest($object_type, $group_name, $locale = null, stri } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1357,13 +1373,16 @@ public function updateWithHttpInfo($object_type, $group_name, $property_group_up try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1496,8 +1515,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1505,8 +1525,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1585,7 +1605,7 @@ public function updateRequest($object_type, $group_name, $property_group_update, if (isset($property_group_update)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($property_group_update)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($property_group_update), JSON_THROW_ON_ERROR); } else { $httpBody = $property_group_update; } @@ -1606,7 +1626,7 @@ public function updateRequest($object_type, $group_name, $property_group_update, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Schemas/Api/CoreApi.php b/codegen/Crm/Schemas/Api/CoreApi.php index c5e9405e7..0cf2abf08 100644 --- a/codegen/Crm/Schemas/Api/CoreApi.php +++ b/codegen/Crm/Schemas/Api/CoreApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Schemas\ApiException; @@ -179,13 +179,16 @@ public function archiveWithHttpInfo($object_type, $archived = false, string $con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -257,8 +260,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -266,8 +270,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -347,7 +351,7 @@ public function archiveRequest($object_type, $archived = false, string $contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -416,13 +420,16 @@ public function archiveAssociationWithHttpInfo($object_type, $association_identi try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -494,8 +501,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -503,8 +511,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -589,7 +597,7 @@ public function archiveAssociationRequest($object_type, $association_identifier, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -657,13 +665,16 @@ public function createWithHttpInfo($object_schema_egg, string $contentType = sel try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -788,8 +799,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -797,8 +809,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -845,7 +857,7 @@ public function createRequest($object_schema_egg, string $contentType = self::co if (isset($object_schema_egg)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($object_schema_egg)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($object_schema_egg), JSON_THROW_ON_ERROR); } else { $httpBody = $object_schema_egg; } @@ -866,7 +878,7 @@ public function createRequest($object_schema_egg, string $contentType = self::co } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -936,13 +948,16 @@ public function createAssociationWithHttpInfo($object_type, $association_definit try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1069,8 +1084,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1078,8 +1094,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1142,7 +1158,7 @@ public function createAssociationRequest($object_type, $association_definition_e if (isset($association_definition_egg)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($association_definition_egg)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($association_definition_egg), JSON_THROW_ON_ERROR); } else { $httpBody = $association_definition_egg; } @@ -1163,7 +1179,7 @@ public function createAssociationRequest($object_type, $association_definition_e } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1231,13 +1247,16 @@ public function getAllWithHttpInfo($archived = false, string $contentType = self try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1362,8 +1381,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1371,8 +1391,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1436,7 +1456,7 @@ public function getAllRequest($archived = false, string $contentType = self::con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1504,13 +1524,16 @@ public function getByIdWithHttpInfo($object_type, string $contentType = self::co try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1635,8 +1658,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1644,8 +1668,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1714,7 +1738,7 @@ public function getByIdRequest($object_type, string $contentType = self::content } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1784,13 +1808,16 @@ public function updateWithHttpInfo($object_type, $object_type_definition_patch, try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1917,8 +1944,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1926,8 +1954,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1990,7 +2018,7 @@ public function updateRequest($object_type, $object_type_definition_patch, strin if (isset($object_type_definition_patch)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($object_type_definition_patch)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($object_type_definition_patch), JSON_THROW_ON_ERROR); } else { $httpBody = $object_type_definition_patch; } @@ -2011,7 +2039,7 @@ public function updateRequest($object_type, $object_type_definition_patch, strin } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Timeline/Api/EventsApi.php b/codegen/Crm/Timeline/Api/EventsApi.php index 8cac886bc..9854babaf 100644 --- a/codegen/Crm/Timeline/Api/EventsApi.php +++ b/codegen/Crm/Timeline/Api/EventsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Timeline\ApiException; @@ -176,13 +176,16 @@ public function createWithHttpInfo($timeline_event, string $contentType = self:: try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -311,8 +314,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -320,8 +324,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -368,7 +372,7 @@ public function createRequest($timeline_event, string $contentType = self::conte if (isset($timeline_event)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($timeline_event)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($timeline_event), JSON_THROW_ON_ERROR); } else { $httpBody = $timeline_event; } @@ -389,7 +393,7 @@ public function createRequest($timeline_event, string $contentType = self::conte } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -460,13 +464,16 @@ public function createBatchWithHttpInfo($batch_input_timeline_event, string $con try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -556,8 +563,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -565,8 +573,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -613,7 +621,7 @@ public function createBatchRequest($batch_input_timeline_event, string $contentT if (isset($batch_input_timeline_event)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_timeline_event)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_timeline_event), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_timeline_event; } @@ -634,7 +642,7 @@ public function createBatchRequest($batch_input_timeline_event, string $contentT } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -708,13 +716,16 @@ public function getByIdWithHttpInfo($event_template_id, $event_id, string $conte try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -845,8 +856,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -854,8 +866,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -940,7 +952,7 @@ public function getByIdRequest($event_template_id, $event_id, string $contentTyp } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1014,13 +1026,16 @@ public function getDetailByIdWithHttpInfo($event_template_id, $event_id, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1151,8 +1166,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1160,8 +1176,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1246,7 +1262,7 @@ public function getDetailByIdRequest($event_template_id, $event_id, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1322,13 +1338,16 @@ public function getRenderByIdWithHttpInfo($event_id, $event_template_id, $detail try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1461,8 +1480,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1470,8 +1490,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1567,7 +1587,7 @@ public function getRenderByIdRequest($event_id, $event_template_id, $detail = nu } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Timeline/Api/TemplatesApi.php b/codegen/Crm/Timeline/Api/TemplatesApi.php index d5a4b1ad9..330bdb060 100644 --- a/codegen/Crm/Timeline/Api/TemplatesApi.php +++ b/codegen/Crm/Timeline/Api/TemplatesApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Timeline\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($event_template_id, $app_id, string $content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -259,8 +262,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -268,8 +272,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -354,7 +358,7 @@ public function archiveRequest($event_template_id, $app_id, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -429,13 +433,16 @@ public function createWithHttpInfo($app_id, $timeline_event_template_create_requ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -566,8 +573,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -575,8 +583,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -639,7 +647,7 @@ public function createRequest($app_id, $timeline_event_template_create_request, if (isset($timeline_event_template_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $timeline_event_template_create_request; } @@ -660,7 +668,7 @@ public function createRequest($app_id, $timeline_event_template_create_request, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -733,13 +741,16 @@ public function getAllWithHttpInfo($app_id, string $contentType = self::contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -868,8 +879,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -877,8 +889,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -947,7 +959,7 @@ public function getAllRequest($app_id, string $contentType = self::contentTypes[ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1022,13 +1034,16 @@ public function getByIdWithHttpInfo($event_template_id, $app_id, string $content try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1159,8 +1174,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1168,8 +1184,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1254,7 +1270,7 @@ public function getByIdRequest($event_template_id, $app_id, string $contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1331,13 +1347,16 @@ public function updateWithHttpInfo($event_template_id, $app_id, $timeline_event_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1470,8 +1489,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1479,8 +1499,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1559,7 +1579,7 @@ public function updateRequest($event_template_id, $app_id, $timeline_event_templ if (isset($timeline_event_template_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $timeline_event_template_update_request; } @@ -1580,7 +1600,7 @@ public function updateRequest($event_template_id, $app_id, $timeline_event_templ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Crm/Timeline/Api/TokensApi.php b/codegen/Crm/Timeline/Api/TokensApi.php index 8c712e317..bde7ce021 100644 --- a/codegen/Crm/Timeline/Api/TokensApi.php +++ b/codegen/Crm/Timeline/Api/TokensApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Crm\Timeline\ApiException; @@ -173,13 +173,16 @@ public function archiveWithHttpInfo($event_template_id, $token_name, $app_id, st try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -257,8 +260,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -266,8 +270,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -368,7 +372,7 @@ public function archiveRequest($event_template_id, $token_name, $app_id, string } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -445,13 +449,16 @@ public function createWithHttpInfo($event_template_id, $app_id, $timeline_event_ try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -584,8 +591,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -593,8 +601,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -673,7 +681,7 @@ public function createRequest($event_template_id, $app_id, $timeline_event_templ if (isset($timeline_event_template_token)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_token)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_token), JSON_THROW_ON_ERROR); } else { $httpBody = $timeline_event_template_token; } @@ -694,7 +702,7 @@ public function createRequest($event_template_id, $app_id, $timeline_event_templ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -773,13 +781,16 @@ public function updateWithHttpInfo($event_template_id, $token_name, $app_id, $ti try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -914,8 +925,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -923,8 +935,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1019,7 +1031,7 @@ public function updateRequest($event_template_id, $token_name, $app_id, $timelin if (isset($timeline_event_template_token_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_token_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($timeline_event_template_token_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $timeline_event_template_token_update_request; } @@ -1040,7 +1052,7 @@ public function updateRequest($event_template_id, $token_name, $app_id, $timelin } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Events/Api/EventsApi.php b/codegen/Events/Api/EventsApi.php index 9e717f671..e75a5bf81 100644 --- a/codegen/Events/Api/EventsApi.php +++ b/codegen/Events/Api/EventsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Events\ApiException; @@ -189,13 +189,16 @@ public function getPageWithHttpInfo($object_type = null, $event_type = null, $af try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -346,8 +349,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -355,8 +359,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -541,7 +545,7 @@ public function getPageRequest($object_type = null, $event_type = null, $after = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -611,13 +615,16 @@ public function getTypesWithHttpInfo(string $contentType = self::contentTypes['g try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -744,8 +751,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -753,8 +761,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -807,7 +815,7 @@ public function getTypesRequest(string $contentType = self::contentTypes['getTyp } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Marketing/Emails/Api/StatisticsApi.php b/codegen/Marketing/Emails/Api/StatisticsApi.php index 502ceab3b..7e00963a2 100644 --- a/codegen/Marketing/Emails/Api/StatisticsApi.php +++ b/codegen/Marketing/Emails/Api/StatisticsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Marketing\Emails\ApiException; @@ -173,13 +173,16 @@ public function getEmailsListWithHttpInfo($start_timestamp = null, $end_timestam try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -314,8 +317,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -323,8 +327,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -421,7 +425,7 @@ public function getEmailsListRequest($start_timestamp = null, $end_timestamp = n } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -499,13 +503,16 @@ public function getHistogramWithHttpInfo($interval = null, $start_timestamp = nu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -640,8 +647,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -649,8 +657,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -747,7 +755,7 @@ public function getHistogramRequest($interval = null, $start_timestamp = null, $ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Marketing/Forms/Api/FormsApi.php b/codegen/Marketing/Forms/Api/FormsApi.php index 2cfbebd73..10fb92fda 100644 --- a/codegen/Marketing/Forms/Api/FormsApi.php +++ b/codegen/Marketing/Forms/Api/FormsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Marketing\Forms\ApiException; @@ -178,13 +178,16 @@ public function archiveWithHttpInfo($form_id, string $contentType = self::conten try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -258,8 +261,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -267,8 +271,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($form_id, string $contentType = self::contentType } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -409,13 +413,16 @@ public function createWithHttpInfo($body, string $contentType = self::contentTyp try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -544,8 +551,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -553,8 +561,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -601,7 +609,7 @@ public function createRequest($body, string $contentType = self::contentTypes['c if (isset($body)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($body)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($body), JSON_THROW_ON_ERROR); } else { $httpBody = $body; } @@ -622,7 +630,7 @@ public function createRequest($body, string $contentType = self::contentTypes['c } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -696,13 +704,16 @@ public function getByIdWithHttpInfo($form_id, $archived = null, string $contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -833,8 +844,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -842,8 +854,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -923,7 +935,7 @@ public function getByIdRequest($form_id, $archived = null, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1001,13 +1013,16 @@ public function getPageWithHttpInfo($after = null, $limit = null, $archived = nu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1142,8 +1157,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1151,8 +1167,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1249,7 +1265,7 @@ public function getPageRequest($after = null, $limit = null, $archived = null, $ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1323,13 +1339,16 @@ public function replaceWithHttpInfo($form_id, $hub_spot_form_definition, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1460,8 +1479,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1469,8 +1489,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1533,7 +1553,7 @@ public function replaceRequest($form_id, $hub_spot_form_definition, string $cont if (isset($hub_spot_form_definition)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($hub_spot_form_definition)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_spot_form_definition), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_spot_form_definition; } @@ -1554,7 +1574,7 @@ public function replaceRequest($form_id, $hub_spot_form_definition, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1628,13 +1648,16 @@ public function updateWithHttpInfo($form_id, $hub_spot_form_definition_patch_req try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1765,8 +1788,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1774,8 +1798,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1838,7 +1862,7 @@ public function updateRequest($form_id, $hub_spot_form_definition_patch_request, if (isset($hub_spot_form_definition_patch_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($hub_spot_form_definition_patch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_spot_form_definition_patch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_spot_form_definition_patch_request; } @@ -1859,7 +1883,7 @@ public function updateRequest($form_id, $hub_spot_form_definition_patch_request, } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Settings/BusinessUnits/Api/BusinessUnitsApi.php b/codegen/Settings/BusinessUnits/Api/BusinessUnitsApi.php index 2c44f8203..86d299275 100644 --- a/codegen/Settings/BusinessUnits/Api/BusinessUnitsApi.php +++ b/codegen/Settings/BusinessUnits/Api/BusinessUnitsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Settings\BusinessUnits\ApiException; @@ -168,13 +168,16 @@ public function getByUserIDWithHttpInfo($user_id, $properties = null, $name = nu try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -307,8 +310,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -316,8 +320,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -408,7 +412,7 @@ public function getByUserIDRequest($user_id, $properties = null, $name = null, s } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Webhooks/Api/SettingsApi.php b/codegen/Webhooks/Api/SettingsApi.php index 726d17826..d13edb189 100644 --- a/codegen/Webhooks/Api/SettingsApi.php +++ b/codegen/Webhooks/Api/SettingsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Webhooks\ApiException; @@ -169,13 +169,16 @@ public function clearWithHttpInfo($app_id, string $contentType = self::contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -249,8 +252,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -258,8 +262,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -328,7 +332,7 @@ public function clearRequest($app_id, string $contentType = self::contentTypes[' } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -403,13 +407,16 @@ public function configureWithHttpInfo($app_id, $settings_change_request, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -540,8 +547,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -549,8 +557,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -613,7 +621,7 @@ public function configureRequest($app_id, $settings_change_request, string $cont if (isset($settings_change_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($settings_change_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($settings_change_request), JSON_THROW_ON_ERROR); } else { $httpBody = $settings_change_request; } @@ -634,7 +642,7 @@ public function configureRequest($app_id, $settings_change_request, string $cont } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -707,13 +715,16 @@ public function getAllWithHttpInfo($app_id, string $contentType = self::contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -842,8 +853,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -851,8 +863,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -921,7 +933,7 @@ public function getAllRequest($app_id, string $contentType = self::contentTypes[ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/codegen/Webhooks/Api/SubscriptionsApi.php b/codegen/Webhooks/Api/SubscriptionsApi.php index f5584c9fb..30140c810 100644 --- a/codegen/Webhooks/Api/SubscriptionsApi.php +++ b/codegen/Webhooks/Api/SubscriptionsApi.php @@ -29,11 +29,11 @@ use GuzzleHttp\Client; use GuzzleHttp\ClientInterface; -use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\MultipartStream; use GuzzleHttp\Psr7\Request; use GuzzleHttp\RequestOptions; +use Psr\Http\Client\NetworkExceptionInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use HubSpot\Client\Webhooks\ApiException; @@ -180,13 +180,16 @@ public function archiveWithHttpInfo($subscription_id, $app_id, string $contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -262,8 +265,9 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -271,8 +275,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -357,7 +361,7 @@ public function archiveRequest($subscription_id, $app_id, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -432,13 +436,16 @@ public function createWithHttpInfo($app_id, $subscription_create_request, string try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -569,8 +576,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -578,8 +586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -642,7 +650,7 @@ public function createRequest($app_id, $subscription_create_request, string $con if (isset($subscription_create_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($subscription_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($subscription_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $subscription_create_request; } @@ -663,7 +671,7 @@ public function createRequest($app_id, $subscription_create_request, string $con } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -736,13 +744,16 @@ public function getAllWithHttpInfo($app_id, string $contentType = self::contentT try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -871,8 +882,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -880,8 +892,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -950,7 +962,7 @@ public function getAllRequest($app_id, string $contentType = self::contentTypes[ } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1025,13 +1037,16 @@ public function getByIdWithHttpInfo($subscription_id, $app_id, string $contentTy try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1162,8 +1177,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1171,8 +1187,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1257,7 +1273,7 @@ public function getByIdRequest($subscription_id, $app_id, string $contentType = } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1334,13 +1350,16 @@ public function updateWithHttpInfo($subscription_id, $app_id, $subscription_patc try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1473,8 +1492,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1482,8 +1502,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1562,7 +1582,7 @@ public function updateRequest($subscription_id, $app_id, $subscription_patch_req if (isset($subscription_patch_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($subscription_patch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($subscription_patch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $subscription_patch_request; } @@ -1583,7 +1603,7 @@ public function updateRequest($subscription_id, $app_id, $subscription_patch_req } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); @@ -1658,13 +1678,16 @@ public function updateBatchWithHttpInfo($app_id, $batch_input_subscription_batch try { $response = $this->client->send($request, $options); } catch (RequestException $e) { + // Guzzle 8 exposes a response only on ResponseException subclasses. + $errorResponse = method_exists($e, 'getResponse') ? $e->getResponse() : null; + throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), - $e->getResponse() ? $e->getResponse()->getHeaders() : null, - $e->getResponse() ? (string) $e->getResponse()->getBody() : null + $errorResponse ? $errorResponse->getHeaders() : null, + $errorResponse ? (string) $errorResponse->getBody() : null ); - } catch (ConnectException $e) { + } catch (NetworkExceptionInterface $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", (int) $e->getCode(), @@ -1809,8 +1832,9 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + // Guzzle 8 exposes a response only on ResponseException subclasses. + $response = method_exists($exception, 'getResponse') ? $exception->getResponse() : null; + $statusCode = $response ? $response->getStatusCode() : 0; throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', @@ -1818,8 +1842,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1882,7 +1906,7 @@ public function updateBatchRequest($app_id, $batch_input_subscription_batch_upda if (isset($batch_input_subscription_batch_update_request)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($batch_input_subscription_batch_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_subscription_batch_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_subscription_batch_update_request; } @@ -1903,7 +1927,7 @@ public function updateBatchRequest($app_id, $batch_input_subscription_batch_upda } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the form parameters - $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + $httpBody = json_encode($formParams, JSON_THROW_ON_ERROR); } else { // for HTTP post (form) $httpBody = ObjectSerializer::buildQuery($formParams); diff --git a/composer.json b/composer.json index 757b50d1c..c421ca739 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "guzzlehttp/guzzle": "^7.3", - "guzzlehttp/psr7": "^1.7 || ^2.0" + "guzzlehttp/guzzle": "^7.3 || ^8.0", + "guzzlehttp/psr7": "^1.7 || ^2.0 || ^3.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.94", diff --git a/lib/Delay.php b/lib/Delay.php index 25e1a2ed5..3ebae62e2 100644 --- a/lib/Delay.php +++ b/lib/Delay.php @@ -19,7 +19,7 @@ public static function getLinearDelayFunction() } /** - * @deprecated pass null as the delay function instead — Guzzle will apply its built-in exponential delay via \GuzzleHttp\RetryMiddleware::exponentialDelay + * @deprecated pass null as the delay function instead - \GuzzleHttp\RetryMiddleware then applies its built-in exponential delay */ public static function getExponentialDelayFunction(int $base) { diff --git a/lib/Http/Request.php b/lib/Http/Request.php index 3323d9e2c..fb8c7c59b 100644 --- a/lib/Http/Request.php +++ b/lib/Http/Request.php @@ -39,7 +39,8 @@ public function __construct(Config $config, array $options = []) if (array_key_exists('defaultJson', $this->options)) { $this->defaultJson = $this->options['defaultJson']; } - $this->method = $this->options['method'] ?? 'GET'; + // Guzzle 7 uppercased request methods, Guzzle 8 sends them verbatim. + $this->method = strtoupper($this->options['method'] ?? 'GET'); $this->initHeaders(); $this->applyAuth(); diff --git a/lib/RetryMiddlewareFactory.php b/lib/RetryMiddlewareFactory.php index 45ccc0e43..6a077422f 100644 --- a/lib/RetryMiddlewareFactory.php +++ b/lib/RetryMiddlewareFactory.php @@ -2,10 +2,11 @@ namespace HubSpot; -use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Middleware; -use GuzzleHttp\Psr7\Request; -use GuzzleHttp\Psr7\Response; +use Psr\Http\Client\NetworkExceptionInterface; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; class RetryMiddlewareFactory { @@ -92,14 +93,14 @@ public static function getRetryFunctionByRanges( ): callable { return function ( $retries, - Request $request, - ?Response $response = null + RequestInterface $request, + ?ResponseInterface $response = null ) use ($ranges, $maxRetries) { if ($retries >= $maxRetries) { return false; } - if (!$response instanceof Response) { + if (!$response instanceof ResponseInterface) { return false; } @@ -130,14 +131,14 @@ public static function getRetryFunction( ): callable { return function ( $retries, - Request $request, - ?Response $response = null + RequestInterface $request, + ?ResponseInterface $response = null ) use ($codes, $maxRetries) { if ($retries >= $maxRetries) { return false; } - if (($response instanceof Response) && in_array($response->getStatusCode(), $codes)) { + if (($response instanceof ResponseInterface) && in_array($response->getStatusCode(), $codes)) { return true; } @@ -151,31 +152,40 @@ public static function getRetryFunctionByConnectionErrors( ): callable { return function ( $retries, - Request $request, - ?Response $response = null, + RequestInterface $request, + ?ResponseInterface $response = null, $exception = null ) use ($maxRetries, $curlErrorCodes) { if ($retries >= $maxRetries) { return false; } - if (!$exception instanceof ConnectException) { - return false; + // Guzzle 7 exposes cURL context; Guzzle 8 exposes only the message. + $context = ($exception instanceof RequestException || $exception instanceof NetworkExceptionInterface) + && method_exists($exception, 'getHandlerContext') + ? $exception->getHandlerContext() + : []; + $errno = $context['errno'] ?? null; + if (!is_numeric($errno) && $exception instanceof \Throwable + && 1 === preg_match('/cURL error\s+(\d+):/i', $exception->getMessage(), $matches)) { + $errno = $matches[1]; } - if (empty($curlErrorCodes)) { - return true; + // Guzzle 7 uses RequestException for send/receive errors (55/56). + // Require cURL context to distinguish them from other request failures. + $legacyTransferError = $exception instanceof RequestException + && is_numeric($context['errno'] ?? null) + && in_array((int) $context['errno'], self::TRANSIENT_CURL_ERROR_CODES, true); + if (!$exception instanceof NetworkExceptionInterface && !$legacyTransferError) { + return false; } - $handlerContext = $exception->getHandlerContext(); - $errno = $handlerContext['errno'] ?? null; - - if (is_numeric($errno) && in_array((int) $errno, $curlErrorCodes, true)) { + if (empty($curlErrorCodes)) { return true; } - if (1 === preg_match('/cURL error\s+(\d+):/i', $exception->getMessage(), $matches)) { - return in_array((int) $matches[1], $curlErrorCodes, true); + if (is_numeric($errno)) { + return in_array((int) $errno, $curlErrorCodes, true); } return false; diff --git a/tests/Unit/GeneratedApiClientTest.php b/tests/Unit/GeneratedApiClientTest.php new file mode 100644 index 000000000..326897928 --- /dev/null +++ b/tests/Unit/GeneratedApiClientTest.php @@ -0,0 +1,190 @@ +setActive(true); + $request = $api->createRequest(123, $input); + $this->assertSame(['active' => true], json_decode((string) $request->getBody(), true)); + } + + public function testWebhooksHandlesResponselessExceptionsOnBothPaths(): void + { + $request = new Request('GET', 'https://api.hubapi.com'); + $exceptions = [new RequestException('No response', $request), new ConnectException('Connection failed', $request)]; + if (class_exists(NetworkException::class)) { + $exceptions[] = new NetworkException('Network failed', $request); + } + foreach ($exceptions as $exception) { + foreach ([false, true] as $async) { + $client = new Client(['handler' => HandlerStack::create(new MockHandler([$exception]))]); + $api = new SubscriptionsApi($client); + + try { + if ($async) { + $api->getAllAsync(123)->wait(); + } else { + $api->getAll(123); + } + $this->fail('Expected ApiException'); + } catch (\HubSpot\Client\Webhooks\ApiException $error) { + $this->assertSame(0, $error->getCode()); + $this->assertNull($error->getResponseHeaders()); + $this->assertNull($error->getResponseBody()); + } + } + } + } + + /** @test */ + public function itSendsAJsonEncodedBody(): void + { + $sent = []; + $api = $this->apiWithMock([new Response(201, ['Content-Type' => 'application/json'], '{"id":"1","properties":{}}')], $sent); + + $input = new SimplePublicObjectInputForCreate(); + $input->setProperties(['email' => 'test@example.com']); + + $api->create($input); + + $this->assertCount(1, $sent); + $this->assertSame('POST', $sent[0]->getMethod()); + $this->assertSame('application/json', $sent[0]->getHeaderLine('Content-Type')); + $this->assertSame( + ['properties' => ['email' => 'test@example.com']], + json_decode((string) $sent[0]->getBody(), true) + ); + } + + /** @test */ + public function itConvertsAnErrorResponseIntoAnApiExceptionWithHeadersAndBody(): void + { + $sent = []; + $api = $this->apiWithMock([new Response(400, ['X-Trace' => 'abc'], '{"message":"bad request"}')], $sent); + + try { + $api->getById('1'); + $this->fail('Expected ApiException to be thrown'); + } catch (ApiException $e) { + $this->assertSame(400, $e->getCode()); + $this->assertSame('{"message":"bad request"}', $e->getResponseBody()); + $this->assertSame(['abc'], $e->getResponseHeaders()['X-Trace']); + } + } + + /** @test */ + public function itConvertsAResponselessRequestExceptionIntoAnApiException(): void + { + $sent = []; + $api = $this->apiWithMock([ + new RequestException('Body could not be read', new Request('GET', 'https://api.hubapi.com')), + ], $sent); + + try { + $api->getById('1'); + $this->fail('Expected ApiException to be thrown'); + } catch (ApiException $e) { + $this->assertStringContainsString('Body could not be read', $e->getMessage()); + $this->assertNull($e->getResponseBody()); + $this->assertNull($e->getResponseHeaders()); + } + } + + /** @test */ + public function itConvertsANetworkFailureIntoAnApiException(): void + { + $sent = []; + $api = $this->apiWithMock([ + new ConnectException('cURL error 7: Failed to connect', new Request('GET', 'https://api.hubapi.com')), + ], $sent); + + try { + $api->getById('1'); + $this->fail('Expected ApiException to be thrown'); + } catch (ApiException $e) { + $this->assertStringContainsString('Failed to connect', $e->getMessage()); + $this->assertNull($e->getResponseBody()); + } + } + + /** @test */ + public function itConvertsAResponselessFailureIntoAnApiExceptionOnTheAsyncPath(): void + { + $sent = []; + $api = $this->apiWithMock([ + new ConnectException('cURL error 7: Failed to connect', new Request('GET', 'https://api.hubapi.com')), + ], $sent); + + $this->expectException(ApiException::class); + + $api->getByIdAsync('1')->wait(); + } + + /** @test */ + public function itConvertsAnErrorResponseIntoAnApiExceptionOnTheAsyncPath(): void + { + $sent = []; + $api = $this->apiWithMock([new Response(404, ['X-Trace' => 'abc'], '{"message":"not found"}')], $sent); + + try { + $api->getByIdAsync('1')->wait(); + $this->fail('Expected ApiException to be thrown'); + } catch (ApiException $e) { + $this->assertSame(404, $e->getCode()); + $this->assertSame('{"message":"not found"}', $e->getResponseBody()); + } + } + + /** + * @param array $queue + * @param array|mixed $sent + */ + private function apiWithMock(array $queue, array &$sent): BasicApi + { + $stack = HandlerStack::create(new MockHandler($queue)); + $stack->push(function (callable $handler) use (&$sent) { + return function (RequestInterface $request, array $options) use ($handler, &$sent) { + $sent[] = $request; + + return $handler($request, $options); + }; + }); + + $config = new Configuration(); + $config->setAccessToken('test-token'); + + return new BasicApi(new Client(['handler' => $stack]), $config); + } +} diff --git a/tests/Unit/Http/RequestTest.php b/tests/Unit/Http/RequestTest.php index 028ea1abb..33b8b611a 100644 --- a/tests/Unit/Http/RequestTest.php +++ b/tests/Unit/Http/RequestTest.php @@ -93,6 +93,17 @@ public function createContactsDefaultJsonFasle(): void ], $request->getOptionsForSending()); } + /** @test */ + public function itNormalizesTheRequestMethodCasing(): void + { + $request = new Request(new Config(), [ + 'path' => '/crm/v3/objects/contacts', + 'method' => 'post', + ]); + + $this->assertSame('POST', $request->getMethod()); + } + protected function getHeaders(Config $config, bool $defaultJson = true): array { $headers = [ diff --git a/tests/Unit/RetryMiddlewareFactoryTest.php b/tests/Unit/RetryMiddlewareFactoryTest.php index 92b137793..20be71ed1 100644 --- a/tests/Unit/RetryMiddlewareFactoryTest.php +++ b/tests/Unit/RetryMiddlewareFactoryTest.php @@ -3,6 +3,8 @@ namespace Hubspot\Tests\Unit; use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\NetworkException; +use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; use HubSpot\RetryMiddlewareFactory; use PHPUnit\Framework\TestCase; @@ -14,23 +16,43 @@ */ class RetryMiddlewareFactoryTest extends TestCase { + public function testRetriesTransferFailuresUsingActualGuzzleExceptionTypes(): void + { + $request = new Request('GET', 'https://api.hubapi.com/test'); + foreach ([52, 55, 56] as $errno) { + if (class_exists(NetworkException::class)) { + $exception = new NetworkException("cURL error {$errno}: transfer failed", $request); + } elseif (52 === $errno) { + $exception = new ConnectException('Transfer failed', $request, null, ['errno' => $errno]); + } else { + $exception = new RequestException('Transfer failed', $request, null, null, ['errno' => $errno]); + } + + $retry = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors(); + $this->assertTrue($retry(0, $request, null, $exception), "cURL error {$errno}"); + $this->assertFalse($retry(5, $request, null, $exception)); + $restricted = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors([7]); + $this->assertFalse($restricted(0, $request, null, $exception)); + $unrestricted = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors([]); + $this->assertTrue($unrestricted(0, $request, null, $exception)); + } + } + /** @test */ - public function itRetriesRetriableConnectionErrorsByErrno(): void + public function itRetriesRetriableConnectionErrorsByMessage(): void { $retry = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors(RetryMiddlewareFactory::TRANSIENT_CURL_ERROR_CODES, 3); $request = new Request('GET', 'https://api.hubapi.com/test'); $exception = new ConnectException( 'cURL error 56: OpenSSL SSL_read unexpected eof while reading', - $request, - null, - ['errno' => 56] + $request ); $this->assertTrue($retry(0, $request, null, $exception)); } /** @test */ - public function itRetriesRetriableConnectionErrorsByMessageWhenErrnoMissing(): void + public function itRetriesRetriableSendErrors(): void { $retry = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors(RetryMiddlewareFactory::TRANSIENT_CURL_ERROR_CODES, 3); $request = new Request('GET', 'https://api.hubapi.com/test'); @@ -49,14 +71,42 @@ public function itDoesNotRetryNonRetriableConnectionErrors(): void $request = new Request('GET', 'https://api.hubapi.com/test'); $exception = new ConnectException( 'cURL error 60: SSL certificate problem', - $request, - null, - ['errno' => 60] + $request ); $this->assertFalse($retry(0, $request, null, $exception)); } + /** @test */ + public function itDoesNotRetryConnectionErrorsWithoutACurlErrno(): void + { + $retry = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors(RetryMiddlewareFactory::TRANSIENT_CURL_ERROR_CODES, 3); + $request = new Request('GET', 'https://api.hubapi.com/test'); + $exception = new ConnectException('Connection failed', $request); + + $this->assertFalse($retry(0, $request, null, $exception)); + } + + /** @test */ + public function itRetriesAnyConnectionErrorWhenNoCurlErrorCodesAreGiven(): void + { + $retry = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors([], 3); + $request = new Request('GET', 'https://api.hubapi.com/test'); + $exception = new ConnectException('Connection failed', $request); + + $this->assertTrue($retry(0, $request, null, $exception)); + } + + /** @test */ + public function itDoesNotRetryExceptionsThatAreNotNetworkFailures(): void + { + $retry = RetryMiddlewareFactory::getRetryFunctionByConnectionErrors(RetryMiddlewareFactory::TRANSIENT_CURL_ERROR_CODES, 3); + $request = new Request('GET', 'https://api.hubapi.com/test'); + $exception = new RequestException('cURL error 56: something else', $request); + + $this->assertFalse($retry(0, $request, null, $exception)); + } + /** @test */ public function itStopsRetryingWhenMaxRetriesReached(): void { @@ -64,9 +114,7 @@ public function itStopsRetryingWhenMaxRetriesReached(): void $request = new Request('GET', 'https://api.hubapi.com/test'); $exception = new ConnectException( 'cURL error 56: OpenSSL SSL_read unexpected eof while reading', - $request, - null, - ['errno' => 56] + $request ); $this->assertFalse($retry(1, $request, null, $exception));