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..1ba377939 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 the exception message, because Guzzle 8 removed `RequestException::getHandlerContext()` and reclassified cURL errors 52, 55 and 56 as `NetworkException` rather than `ConnectException`. As a side effect, cURL errors 55 and 56 are now retried on Guzzle 7 as well, which is what `TRANSIENT_CURL_ERROR_CODES` always documented. +- `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/Automation/Actions/Api/CallbacksApi.php b/codegen/Automation/Actions/Api/CallbacksApi.php index c62cbb2de..bacc110e3 100644 --- a/codegen/Automation/Actions/Api/CallbacksApi.php +++ b/codegen/Automation/Actions/Api/CallbacksApi.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\Automation\Actions\ApiException; @@ -168,13 +168,16 @@ public function completeWithHttpInfo($callback_id, $callback_completion_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(), @@ -250,8 +253,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)', @@ -259,8 +263,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -323,7 +327,7 @@ public function completeRequest($callback_id, $callback_completion_request, stri if (isset($callback_completion_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($callback_completion_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($callback_completion_request), JSON_THROW_ON_ERROR); } else { $httpBody = $callback_completion_request; } @@ -344,7 +348,7 @@ public function completeRequest($callback_id, $callback_completion_request, 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); @@ -415,13 +419,16 @@ public function completeBatchWithHttpInfo($batch_input_callback_completion_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(), @@ -495,8 +502,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)', @@ -504,8 +512,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -552,7 +560,7 @@ public function completeBatchRequest($batch_input_callback_completion_batch_requ if (isset($batch_input_callback_completion_batch_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_callback_completion_batch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_callback_completion_batch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_callback_completion_batch_request; } @@ -573,7 +581,7 @@ public function completeBatchRequest($batch_input_callback_completion_batch_requ } 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/Automation/Actions/Api/DefinitionsApi.php b/codegen/Automation/Actions/Api/DefinitionsApi.php index 4b05bc43c..20847fd81 100644 --- a/codegen/Automation/Actions/Api/DefinitionsApi.php +++ b/codegen/Automation/Actions/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\Automation\Actions\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($definition_id, $app_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(), @@ -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($definition_id, $app_id, string $contentType = se } 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, $public_action_definition_egg, 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(), @@ -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, $public_action_definition_egg, string $co if (isset($public_action_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($public_action_definition_egg)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_action_definition_egg), JSON_THROW_ON_ERROR); } else { $httpBody = $public_action_definition_egg; } @@ -660,7 +668,7 @@ public function createRequest($app_id, $public_action_definition_egg, 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); @@ -737,13 +745,16 @@ public function getByIdWithHttpInfo($definition_id, $app_id, $archived = false, 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 ); } ); @@ -982,7 +994,7 @@ public function getByIdRequest($definition_id, $app_id, $archived = false, 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); @@ -1061,13 +1073,16 @@ public function getPageWithHttpInfo($app_id, $limit = null, $after = null, $arch 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(), @@ -1202,8 +1217,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)', @@ -1211,8 +1227,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1314,7 +1330,7 @@ public function getPageRequest($app_id, $limit = null, $after = null, $archived } 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); @@ -1391,13 +1407,16 @@ public function updateWithHttpInfo($definition_id, $app_id, $public_action_defin 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(), @@ -1530,8 +1549,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)', @@ -1539,8 +1559,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1619,7 +1639,7 @@ public function updateRequest($definition_id, $app_id, $public_action_definition if (isset($public_action_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($public_action_definition_patch)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_action_definition_patch), JSON_THROW_ON_ERROR); } else { $httpBody = $public_action_definition_patch; } @@ -1640,7 +1660,7 @@ public function updateRequest($definition_id, $app_id, $public_action_definition } 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/Automation/Actions/Api/FunctionsApi.php b/codegen/Automation/Actions/Api/FunctionsApi.php index 0b0f67805..c07743e43 100644 --- a/codegen/Automation/Actions/Api/FunctionsApi.php +++ b/codegen/Automation/Actions/Api/FunctionsApi.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\Automation\Actions\ApiException; @@ -187,13 +187,16 @@ public function archiveWithHttpInfo($definition_id, $function_type, $function_id 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(), @@ -273,8 +276,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)', @@ -282,8 +286,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -400,7 +404,7 @@ public function archiveRequest($definition_id, $function_type, $function_id, $ap } 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); @@ -476,13 +480,16 @@ public function archiveByFunctionTypeWithHttpInfo($definition_id, $function_type 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(), @@ -560,8 +567,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)', @@ -569,8 +577,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 archiveByFunctionTypeRequest($definition_id, $function_type, $ap } 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); @@ -752,13 +760,16 @@ public function createOrReplaceWithHttpInfo($definition_id, $function_type, $fun 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(), @@ -895,8 +906,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)', @@ -904,8 +916,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1016,7 +1028,7 @@ public function createOrReplaceRequest($definition_id, $function_type, $function 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; } @@ -1037,7 +1049,7 @@ public function createOrReplaceRequest($definition_id, $function_type, $function } 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); @@ -1116,13 +1128,16 @@ public function createOrReplaceByFunctionTypeWithHttpInfo($definition_id, $funct 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(), @@ -1257,8 +1272,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)', @@ -1266,8 +1282,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1362,7 +1378,7 @@ public function createOrReplaceByFunctionTypeRequest($definition_id, $function_t 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; } @@ -1383,7 +1399,7 @@ public function createOrReplaceByFunctionTypeRequest($definition_id, $function_t } 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); @@ -1460,13 +1476,16 @@ public function getByFunctionTypeWithHttpInfo($definition_id, $function_type, $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(), @@ -1599,8 +1618,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)', @@ -1608,8 +1628,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1710,7 +1730,7 @@ public function getByFunctionTypeRequest($definition_id, $function_type, $app_id } 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); @@ -1789,13 +1809,16 @@ public function getByIdWithHttpInfo($definition_id, $function_type, $function_id 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(), @@ -1930,8 +1953,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)', @@ -1939,8 +1963,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2057,7 +2081,7 @@ public function getByIdRequest($definition_id, $function_type, $function_id, $ap } 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); @@ -2132,13 +2156,16 @@ public function getPageWithHttpInfo($definition_id, $app_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(), @@ -2269,8 +2296,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)', @@ -2278,8 +2306,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2364,7 +2392,7 @@ public function getPageRequest($definition_id, $app_id, string $contentType = se } 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/Automation/Actions/Api/RevisionsApi.php b/codegen/Automation/Actions/Api/RevisionsApi.php index dc90f8820..54e1beded 100644 --- a/codegen/Automation/Actions/Api/RevisionsApi.php +++ b/codegen/Automation/Actions/Api/RevisionsApi.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\Automation\Actions\ApiException; @@ -171,13 +171,16 @@ public function getByIdWithHttpInfo($definition_id, $revision_id, $app_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(), @@ -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 ); } ); @@ -421,7 +425,7 @@ public function getByIdRequest($definition_id, $revision_id, $app_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); @@ -500,13 +504,16 @@ public function getPageWithHttpInfo($definition_id, $app_id, $limit = null, $aft 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(), @@ -641,8 +648,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)', @@ -650,8 +658,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -758,7 +766,7 @@ public function getPageRequest($definition_id, $app_id, $limit = 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); 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/BlogPosts/Api/BasicApi.php b/codegen/Cms/Blogs/BlogPosts/Api/BasicApi.php index 29c06aa46..8ed7dcbd2 100644 --- a/codegen/Cms/Blogs/BlogPosts/Api/BasicApi.php +++ b/codegen/Cms/Blogs/BlogPosts/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\Cms\Blogs\BlogPosts\ApiException; @@ -207,13 +207,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(), @@ -289,8 +292,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)', @@ -298,8 +302,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -379,7 +383,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); @@ -451,13 +455,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(), @@ -586,8 +593,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)', @@ -595,8 +603,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -643,7 +651,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; } @@ -664,7 +672,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); @@ -736,13 +744,16 @@ public function createWithHttpInfo($blog_post, 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(), @@ -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 ); } ); @@ -928,7 +940,7 @@ public function createRequest($blog_post, string $contentType = self::contentTyp if (isset($blog_post)) { 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_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_post), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_post; } @@ -949,7 +961,7 @@ public function createRequest($blog_post, 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); @@ -1025,13 +1037,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(), @@ -1164,8 +1179,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)', @@ -1173,8 +1189,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1265,7 +1281,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); @@ -1337,13 +1353,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(), @@ -1472,8 +1491,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)', @@ -1481,8 +1501,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1551,7 +1571,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); @@ -1643,13 +1663,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(), @@ -1798,8 +1821,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)', @@ -1807,8 +1831,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1982,7 +2006,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); @@ -2056,13 +2080,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(), @@ -2193,8 +2220,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)', @@ -2202,8 +2230,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2288,7 +2316,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); @@ -2366,13 +2394,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(), @@ -2507,8 +2538,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)', @@ -2516,8 +2548,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2619,7 +2651,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); @@ -2690,13 +2722,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(), @@ -2770,8 +2805,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)', @@ -2779,8 +2815,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2849,7 +2885,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); @@ -2920,13 +2956,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(), @@ -3000,8 +3039,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)', @@ -3009,8 +3049,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3079,7 +3119,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); @@ -3153,13 +3193,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(), @@ -3290,8 +3333,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)', @@ -3299,8 +3343,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3385,7 +3429,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); @@ -3459,13 +3503,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(), @@ -3596,8 +3643,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)', @@ -3605,8 +3653,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3691,7 +3739,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); @@ -3762,13 +3810,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(), @@ -3842,8 +3893,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)', @@ -3851,8 +3903,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3899,7 +3951,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; } @@ -3920,7 +3972,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); @@ -3996,13 +4048,16 @@ public function updateWithHttpInfo($object_id, $blog_post, $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(), @@ -4135,8 +4190,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)', @@ -4144,8 +4200,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4219,7 +4275,7 @@ public function updateRequest($object_id, $blog_post, $archived = null, string $ if (isset($blog_post)) { 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_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_post), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_post; } @@ -4240,7 +4296,7 @@ public function updateRequest($object_id, $blog_post, $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); @@ -4314,13 +4370,16 @@ public function updateDraftWithHttpInfo($object_id, $blog_post, 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(), @@ -4451,8 +4510,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)', @@ -4460,8 +4520,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4524,7 +4584,7 @@ public function updateDraftRequest($object_id, $blog_post, string $contentType = if (isset($blog_post)) { 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_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_post), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_post; } @@ -4545,7 +4605,7 @@ public function updateDraftRequest($object_id, $blog_post, 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/Cms/Blogs/BlogPosts/Api/BatchApi.php b/codegen/Cms/Blogs/BlogPosts/Api/BatchApi.php index ab61c01ce..f7b1f67a5 100644 --- a/codegen/Cms/Blogs/BlogPosts/Api/BatchApi.php +++ b/codegen/Cms/Blogs/BlogPosts/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\Cms\Blogs\BlogPosts\ApiException; @@ -172,13 +172,16 @@ public function archiveWithHttpInfo($batch_input_string, 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(), @@ -252,8 +255,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)', @@ -261,8 +265,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -309,7 +313,7 @@ public function archiveRequest($batch_input_string, string $contentType = self:: 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; } @@ -330,7 +334,7 @@ public function archiveRequest($batch_input_string, 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); @@ -402,13 +406,16 @@ public function createWithHttpInfo($batch_input_blog_post, 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(), @@ -551,8 +558,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)', @@ -560,8 +568,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -608,7 +616,7 @@ public function createRequest($batch_input_blog_post, string $contentType = self if (isset($batch_input_blog_post)) { 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_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_blog_post), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_blog_post; } @@ -629,7 +637,7 @@ public function createRequest($batch_input_blog_post, 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); @@ -703,13 +711,16 @@ public function readWithHttpInfo($batch_input_string, $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(), @@ -854,8 +865,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)', @@ -863,8 +875,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -922,7 +934,7 @@ public function readRequest($batch_input_string, $archived = null, string $conte 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; } @@ -943,7 +955,7 @@ public function readRequest($batch_input_string, $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); @@ -1017,13 +1029,16 @@ public function updateWithHttpInfo($batch_input_json_node, $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(), @@ -1168,8 +1183,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)', @@ -1177,8 +1193,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1236,7 +1252,7 @@ public function updateRequest($batch_input_json_node, $archived = null, string $ 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; } @@ -1257,7 +1273,7 @@ public function updateRequest($batch_input_json_node, $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); diff --git a/codegen/Cms/Blogs/BlogPosts/Api/MultiLanguageApi.php b/codegen/Cms/Blogs/BlogPosts/Api/MultiLanguageApi.php index 207728ca5..df435828c 100644 --- a/codegen/Cms/Blogs/BlogPosts/Api/MultiLanguageApi.php +++ b/codegen/Cms/Blogs/BlogPosts/Api/MultiLanguageApi.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\BlogPosts\ApiException; @@ -175,13 +175,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(), @@ -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 ); } ); @@ -312,7 +316,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; } @@ -333,7 +337,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); @@ -405,13 +409,16 @@ public function createLangVariationWithHttpInfo($blog_post_language_clone_reques 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 ); } ); @@ -597,7 +605,7 @@ public function createLangVariationRequest($blog_post_language_clone_request_v_n if (isset($blog_post_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($blog_post_language_clone_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($blog_post_language_clone_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $blog_post_language_clone_request_v_next; } @@ -618,7 +626,7 @@ public function createLangVariationRequest($blog_post_language_clone_request_v_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); @@ -689,13 +697,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(), @@ -769,8 +780,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)', @@ -778,8 +790,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -826,7 +838,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; } @@ -847,7 +859,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); @@ -918,13 +930,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(), @@ -998,8 +1013,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)', @@ -1007,8 +1023,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1055,7 +1071,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; } @@ -1076,7 +1092,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); @@ -1147,13 +1163,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(), @@ -1227,8 +1246,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)', @@ -1236,8 +1256,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1284,7 +1304,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; } @@ -1305,7 +1325,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/RowsApi.php b/codegen/Cms/Hubdb/Api/RowsApi.php index f0ddc09c7..d0d0e62c2 100644 --- a/codegen/Cms/Hubdb/Api/RowsApi.php +++ b/codegen/Cms/Hubdb/Api/RowsApi.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; @@ -192,13 +192,16 @@ public function cloneDraftTableRowWithHttpInfo($table_id_or_name, $row_id, $name 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(), @@ -331,8 +334,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)', @@ -340,8 +344,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -440,7 +444,7 @@ public function cloneDraftTableRowRequest($table_id_or_name, $row_id, $name = 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); @@ -514,13 +518,16 @@ public function createTableRowWithHttpInfo($table_id_or_name, $hub_db_table_row_ 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(), @@ -651,8 +658,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)', @@ -660,8 +668,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -724,7 +732,7 @@ public function createTableRowRequest($table_id_or_name, $hub_db_table_row_v3_re if (isset($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($hub_db_table_row_v3_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_db_table_row_v3_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_db_table_row_v3_request; } @@ -745,7 +753,7 @@ public function createTableRowRequest($table_id_or_name, $hub_db_table_row_v3_re } 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); @@ -821,13 +829,16 @@ public function getDraftTableRowByIdWithHttpInfo($table_id_or_name, $row_id, $ar 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(), @@ -960,8 +971,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)', @@ -969,8 +981,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1069,7 +1081,7 @@ public function getDraftTableRowByIdRequest($table_id_or_name, $row_id, $archive } 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); @@ -1145,13 +1157,16 @@ public function getTableRowWithHttpInfo($table_id_or_name, $row_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(), @@ -1284,8 +1299,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)', @@ -1293,8 +1309,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1393,7 +1409,7 @@ public function getTableRowRequest($table_id_or_name, $row_id, $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); @@ -1477,13 +1493,16 @@ public function getTableRowsWithHttpInfo($table_id_or_name, $sort = null, $after 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(), @@ -1624,8 +1643,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)', @@ -1633,8 +1653,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1769,7 +1789,7 @@ public function getTableRowsRequest($table_id_or_name, $sort = null, $after = 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); @@ -1842,13 +1862,16 @@ public function purgeDraftTableRowWithHttpInfo($table_id_or_name, $row_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(), @@ -1924,8 +1947,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)', @@ -1933,8 +1957,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2022,7 +2046,7 @@ public function purgeDraftTableRowRequest($table_id_or_name, $row_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); @@ -2106,13 +2130,16 @@ public function readDraftTableRowsWithHttpInfo($table_id_or_name, $sort = 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(), @@ -2253,8 +2280,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)', @@ -2262,8 +2290,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2398,7 +2426,7 @@ public function readDraftTableRowsRequest($table_id_or_name, $sort = null, $afte } 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); @@ -2474,13 +2502,16 @@ public function replaceDraftTableRowWithHttpInfo($table_id_or_name, $row_id, $hu 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(), @@ -2613,8 +2644,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)', @@ -2622,8 +2654,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2705,7 +2737,7 @@ public function replaceDraftTableRowRequest($table_id_or_name, $row_id, $hub_db_ if (isset($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($hub_db_table_row_v3_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_db_table_row_v3_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_db_table_row_v3_request; } @@ -2726,7 +2758,7 @@ public function replaceDraftTableRowRequest($table_id_or_name, $row_id, $hub_db_ } 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); @@ -2802,13 +2834,16 @@ public function updateDraftTableRowWithHttpInfo($table_id_or_name, $row_id, $hub 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(), @@ -2941,8 +2976,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)', @@ -2950,8 +2986,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3033,7 +3069,7 @@ public function updateDraftTableRowRequest($table_id_or_name, $row_id, $hub_db_t if (isset($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($hub_db_table_row_v3_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_db_table_row_v3_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_db_table_row_v3_request; } @@ -3054,7 +3090,7 @@ public function updateDraftTableRowRequest($table_id_or_name, $row_id, $hub_db_t } 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/Hubdb/Api/TablesApi.php b/codegen/Cms/Hubdb/Api/TablesApi.php index d01fed81a..d5e1933e2 100644 --- a/codegen/Cms/Hubdb/Api/TablesApi.php +++ b/codegen/Cms/Hubdb/Api/TablesApi.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; @@ -205,13 +205,16 @@ public function archiveTableWithHttpInfo($table_id_or_name, 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(), @@ -285,8 +288,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)', @@ -294,8 +298,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -364,7 +368,7 @@ public function archiveTableRequest($table_id_or_name, 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); @@ -438,13 +442,16 @@ public function cloneDraftTableWithHttpInfo($table_id_or_name, $hub_db_table_clo 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(), @@ -575,8 +582,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)', @@ -584,8 +592,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 cloneDraftTableRequest($table_id_or_name, $hub_db_table_clone_re if (isset($hub_db_table_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($hub_db_table_clone_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_db_table_clone_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_db_table_clone_request; } @@ -669,7 +677,7 @@ public function cloneDraftTableRequest($table_id_or_name, $hub_db_table_clone_re } 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 createTableWithHttpInfo($hub_db_table_v3_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(), @@ -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 createTableRequest($hub_db_table_v3_request, string $contentType if (isset($hub_db_table_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($hub_db_table_v3_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_db_table_v3_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_db_table_v3_request; } @@ -954,7 +966,7 @@ public function createTableRequest($hub_db_table_v3_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); @@ -1028,13 +1040,16 @@ public function exportDraftTableWithHttpInfo($table_id_or_name, $format = 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(), @@ -1165,8 +1180,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)', @@ -1174,8 +1190,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1255,7 +1271,7 @@ public function exportDraftTableRequest($table_id_or_name, $format = null, 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); @@ -1329,13 +1345,16 @@ public function exportTableWithHttpInfo($table_id_or_name, $format = null, 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(), @@ -1466,8 +1485,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)', @@ -1475,8 +1495,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1556,7 +1576,7 @@ public function exportTableRequest($table_id_or_name, $format = null, 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); @@ -1650,13 +1670,16 @@ public function getAllDraftTablesWithHttpInfo($sort = null, $after = null, $limi 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(), @@ -1807,8 +1830,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)', @@ -1816,8 +1840,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2002,7 +2026,7 @@ public function getAllDraftTablesRequest($sort = null, $after = null, $limit = 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); @@ -2096,13 +2120,16 @@ public function getAllTablesWithHttpInfo($sort = null, $after = null, $limit = 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(), @@ -2253,8 +2280,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)', @@ -2262,8 +2290,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2448,7 +2476,7 @@ public function getAllTablesRequest($sort = null, $after = null, $limit = 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); @@ -2526,13 +2554,16 @@ public function getDraftTableDetailsByIdWithHttpInfo($table_id_or_name, $is_get_ 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(), @@ -2667,8 +2698,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)', @@ -2676,8 +2708,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2779,7 +2811,7 @@ public function getDraftTableDetailsByIdRequest($table_id_or_name, $is_get_local } 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); @@ -2857,13 +2889,16 @@ public function getTableDetailsWithHttpInfo($table_id_or_name, $is_get_localized 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(), @@ -2998,8 +3033,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)', @@ -3007,8 +3043,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3110,7 +3146,7 @@ public function getTableDetailsRequest($table_id_or_name, $is_get_localized_sche } 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); @@ -3186,13 +3222,16 @@ public function importDraftTableWithHttpInfo($table_id_or_name, $config = 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(), @@ -3325,8 +3364,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)', @@ -3334,8 +3374,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3419,7 +3459,7 @@ public function importDraftTableRequest($table_id_or_name, $config = null, $file } 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); @@ -3493,13 +3533,16 @@ public function publishDraftTableWithHttpInfo($table_id_or_name, $include_foreig 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(), @@ -3630,8 +3673,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)', @@ -3639,8 +3683,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3720,7 +3764,7 @@ public function publishDraftTableRequest($table_id_or_name, $include_foreign_ids } 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); @@ -3793,13 +3837,16 @@ public function removeTableVersionWithHttpInfo($table_id_or_name, $version_id, 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(), @@ -3875,8 +3922,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)', @@ -3884,8 +3932,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3973,7 +4021,7 @@ public function removeTableVersionRequest($table_id_or_name, $version_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); @@ -4047,13 +4095,16 @@ public function resetDraftTableWithHttpInfo($table_id_or_name, $include_foreign_ 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(), @@ -4184,8 +4235,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)', @@ -4193,8 +4245,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4274,7 +4326,7 @@ public function resetDraftTableRequest($table_id_or_name, $include_foreign_ids = } 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); @@ -4348,13 +4400,16 @@ public function unpublishTableWithHttpInfo($table_id_or_name, $include_foreign_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(), @@ -4485,8 +4540,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)', @@ -4494,8 +4550,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4575,7 +4631,7 @@ public function unpublishTableRequest($table_id_or_name, $include_foreign_ids = } 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); @@ -4655,13 +4711,16 @@ public function updateDraftTableWithHttpInfo($table_id_or_name, $hub_db_table_v3 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(), @@ -4798,8 +4857,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)', @@ -4807,8 +4867,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4904,7 +4964,7 @@ public function updateDraftTableRequest($table_id_or_name, $hub_db_table_v3_requ if (isset($hub_db_table_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($hub_db_table_v3_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($hub_db_table_v3_request), JSON_THROW_ON_ERROR); } else { $httpBody = $hub_db_table_v3_request; } @@ -4925,7 +4985,7 @@ public function updateDraftTableRequest($table_id_or_name, $hub_db_table_v3_requ } 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/LandingPagesApi.php b/codegen/Cms/Pages/Api/LandingPagesApi.php index 7e358a18c..0e7e51d5c 100644 --- a/codegen/Cms/Pages/Api/LandingPagesApi.php +++ b/codegen/Cms/Pages/Api/LandingPagesApi.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; @@ -279,13 +279,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(), @@ -361,8 +364,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)', @@ -370,8 +374,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -451,7 +455,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); @@ -522,13 +526,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(), @@ -602,8 +609,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)', @@ -611,8 +619,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -659,7 +667,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; } @@ -680,7 +688,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); @@ -753,13 +761,16 @@ public function archiveFolderWithHttpInfo($object_id, $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(), @@ -835,8 +846,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)', @@ -844,8 +856,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -925,7 +937,7 @@ public function archiveFolderRequest($object_id, $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); @@ -996,13 +1008,16 @@ public function archiveFoldersWithHttpInfo($batch_input_string, 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(), @@ -1076,8 +1091,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)', @@ -1085,8 +1101,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1133,7 +1149,7 @@ public function archiveFoldersRequest($batch_input_string, string $contentType = 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; } @@ -1154,7 +1170,7 @@ public function archiveFoldersRequest($batch_input_string, 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); @@ -1225,13 +1241,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(), @@ -1305,8 +1324,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)', @@ -1314,8 +1334,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1362,7 +1382,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; } @@ -1383,7 +1403,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); @@ -1455,13 +1475,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(), @@ -1590,8 +1613,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)', @@ -1599,8 +1623,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1647,7 +1671,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; } @@ -1668,7 +1692,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); @@ -1739,13 +1763,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(), @@ -1827,8 +1854,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)', @@ -1836,8 +1864,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1884,7 +1912,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; } @@ -1905,7 +1933,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); @@ -1977,13 +2005,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(), @@ -2112,8 +2143,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)', @@ -2121,8 +2153,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2169,7 +2201,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; } @@ -2190,7 +2222,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); @@ -2262,13 +2294,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(), @@ -2411,8 +2446,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)', @@ -2420,8 +2456,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2468,7 +2504,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; } @@ -2489,7 +2525,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); @@ -2561,13 +2597,16 @@ public function createFolderWithHttpInfo($content_folder, 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(), @@ -2696,8 +2735,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)', @@ -2705,8 +2745,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2753,7 +2793,7 @@ public function createFolderRequest($content_folder, string $contentType = self: if (isset($content_folder)) { 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_folder)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($content_folder), JSON_THROW_ON_ERROR); } else { $httpBody = $content_folder; } @@ -2774,7 +2814,7 @@ public function createFolderRequest($content_folder, 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); @@ -2846,13 +2886,16 @@ public function createFoldersWithHttpInfo($batch_input_content_folder, 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(), @@ -2995,8 +3038,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)', @@ -3004,8 +3048,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3052,7 +3096,7 @@ public function createFoldersRequest($batch_input_content_folder, string $conten if (isset($batch_input_content_folder)) { 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_content_folder)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_content_folder), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_content_folder; } @@ -3073,7 +3117,7 @@ public function createFoldersRequest($batch_input_content_folder, 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); @@ -3145,13 +3189,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(), @@ -3280,8 +3327,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)', @@ -3289,8 +3337,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3337,7 +3385,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; } @@ -3358,7 +3406,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); @@ -3429,13 +3477,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(), @@ -3509,8 +3560,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)', @@ -3518,8 +3570,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3566,7 +3618,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; } @@ -3587,7 +3639,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); @@ -3658,13 +3710,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(), @@ -3738,8 +3793,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)', @@ -3747,8 +3803,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3795,7 +3851,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; } @@ -3816,7 +3872,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); @@ -3892,13 +3948,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(), @@ -4031,8 +4090,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)', @@ -4040,8 +4100,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4132,7 +4192,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); @@ -4204,13 +4264,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(), @@ -4339,8 +4402,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)', @@ -4348,8 +4412,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4418,7 +4482,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); @@ -4494,13 +4558,16 @@ public function getFolderByIdWithHttpInfo($object_id, $archived = null, $propert 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(), @@ -4633,8 +4700,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)', @@ -4642,8 +4710,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4734,7 +4802,7 @@ public function getFolderByIdRequest($object_id, $archived = null, $property = 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); @@ -4808,13 +4876,16 @@ public function getFolderPreviousVersionWithHttpInfo($object_id, $revision_id, 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(), @@ -4945,8 +5016,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)', @@ -4954,8 +5026,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5040,7 +5112,7 @@ public function getFolderPreviousVersionRequest($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); @@ -5118,13 +5190,16 @@ public function getFolderPreviousVersionsWithHttpInfo($object_id, $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(), @@ -5259,8 +5334,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)', @@ -5268,8 +5344,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5371,7 +5447,7 @@ public function getFolderPreviousVersionsRequest($object_id, $after = null, $bef } 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); @@ -5463,13 +5539,16 @@ public function getFoldersPageWithHttpInfo($created_at = null, $created_after = 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(), @@ -5618,8 +5697,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)', @@ -5627,8 +5707,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5802,7 +5882,7 @@ public function getFoldersPageRequest($created_at = null, $created_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); @@ -5894,13 +5974,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(), @@ -6049,8 +6132,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)', @@ -6058,8 +6142,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6233,7 +6317,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); @@ -6307,13 +6391,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(), @@ -6444,8 +6531,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)', @@ -6453,8 +6541,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6539,7 +6627,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); @@ -6617,13 +6705,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(), @@ -6758,8 +6849,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)', @@ -6767,8 +6859,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -6870,7 +6962,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); @@ -6941,13 +7033,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(), @@ -7021,8 +7116,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)', @@ -7030,8 +7126,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7100,7 +7196,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); @@ -7174,13 +7270,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(), @@ -7325,8 +7424,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)', @@ -7334,8 +7434,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7393,7 +7493,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; } @@ -7414,7 +7514,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); @@ -7488,13 +7588,16 @@ public function readFoldersWithHttpInfo($batch_input_string, $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(), @@ -7639,8 +7742,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)', @@ -7648,8 +7752,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7707,7 +7811,7 @@ public function readFoldersRequest($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; } @@ -7728,7 +7832,7 @@ public function readFoldersRequest($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); @@ -7799,13 +7903,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(), @@ -7879,8 +7986,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)', @@ -7888,8 +7996,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -7936,7 +8044,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; } @@ -7957,7 +8065,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); @@ -8028,13 +8136,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(), @@ -8108,8 +8219,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)', @@ -8117,8 +8229,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -8187,7 +8299,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); @@ -8261,13 +8373,16 @@ public function restoreFolderPreviousVersionWithHttpInfo($object_id, $revision_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(), @@ -8398,8 +8513,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)', @@ -8407,8 +8523,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -8493,7 +8609,7 @@ public function restoreFolderPreviousVersionRequest($object_id, $revision_id, 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); @@ -8567,13 +8683,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(), @@ -8704,8 +8823,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)', @@ -8713,8 +8833,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -8799,7 +8919,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); @@ -8873,13 +8993,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(), @@ -9010,8 +9133,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)', @@ -9019,8 +9143,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -9105,7 +9229,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); @@ -9176,13 +9300,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(), @@ -9256,8 +9383,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)', @@ -9265,8 +9393,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -9313,7 +9441,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; } @@ -9334,7 +9462,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); @@ -9405,13 +9533,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(), @@ -9485,8 +9616,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)', @@ -9494,8 +9626,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -9542,7 +9674,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; } @@ -9563,7 +9695,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); @@ -9639,13 +9771,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(), @@ -9778,8 +9913,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)', @@ -9787,8 +9923,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -9862,7 +9998,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; } @@ -9883,7 +10019,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); @@ -9957,13 +10093,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(), @@ -10108,8 +10247,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)', @@ -10117,8 +10257,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -10176,7 +10316,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; } @@ -10197,7 +10337,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); @@ -10271,13 +10411,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(), @@ -10408,8 +10551,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)', @@ -10417,8 +10561,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -10481,7 +10625,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; } @@ -10502,7 +10646,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); @@ -10578,13 +10722,16 @@ public function updateFolderWithHttpInfo($object_id, $content_folder, $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(), @@ -10717,8 +10864,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)', @@ -10726,8 +10874,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -10801,7 +10949,7 @@ public function updateFolderRequest($object_id, $content_folder, $archived = nul if (isset($content_folder)) { 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_folder)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($content_folder), JSON_THROW_ON_ERROR); } else { $httpBody = $content_folder; } @@ -10822,7 +10970,7 @@ public function updateFolderRequest($object_id, $content_folder, $archived = nul } 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); @@ -10896,13 +11044,16 @@ public function updateFoldersWithHttpInfo($batch_input_json_node, $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(), @@ -11047,8 +11198,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)', @@ -11056,8 +11208,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -11115,7 +11267,7 @@ public function updateFoldersRequest($batch_input_json_node, $archived = null, s 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; } @@ -11136,7 +11288,7 @@ public function updateFoldersRequest($batch_input_json_node, $archived = 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); @@ -11207,13 +11359,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(), @@ -11287,8 +11442,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)', @@ -11296,8 +11452,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -11344,7 +11500,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; } @@ -11365,7 +11521,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/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/Api/BatchApi.php b/codegen/Crm/Associations/Api/BatchApi.php index 94f34adf0..49c721af2 100644 --- a/codegen/Crm/Associations/Api/BatchApi.php +++ b/codegen/Crm/Associations/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\Associations\ApiException; @@ -173,13 +173,16 @@ public function archiveWithHttpInfo($from_object_type, $to_object_type, $batch_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(), @@ -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 ); } ); @@ -346,7 +350,7 @@ public function archiveRequest($from_object_type, $to_object_type, $batch_input_ if (isset($batch_input_public_association)) { 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)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association; } @@ -367,7 +371,7 @@ public function archiveRequest($from_object_type, $to_object_type, $batch_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); @@ -443,13 +447,16 @@ public function createWithHttpInfo($from_object_type, $to_object_type, $batch_in 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(), @@ -596,8 +603,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)', @@ -605,8 +613,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -685,7 +693,7 @@ public function createRequest($from_object_type, $to_object_type, $batch_input_p if (isset($batch_input_public_association)) { 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)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association; } @@ -706,7 +714,7 @@ public function createRequest($from_object_type, $to_object_type, $batch_input_p } 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); @@ -782,13 +790,16 @@ public function readWithHttpInfo($from_object_type, $to_object_type, $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(), @@ -935,8 +946,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)', @@ -944,8 +956,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1024,7 +1036,7 @@ public function readRequest($from_object_type, $to_object_type, $batch_input_pub if (isset($batch_input_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_public_object_id)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_object_id), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_object_id; } @@ -1045,7 +1057,7 @@ public function readRequest($from_object_type, $to_object_type, $batch_input_pub } 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/Api/BasicApi.php b/codegen/Crm/Associations/V4/Api/BasicApi.php index 172336e92..2e0f62adc 100644 --- a/codegen/Crm/Associations/V4/Api/BasicApi.php +++ b/codegen/Crm/Associations/V4/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\Associations\V4\ApiException; @@ -178,13 +178,16 @@ public function archiveWithHttpInfo($object_type, $object_id, $to_object_type, $ 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(), @@ -264,8 +267,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)', @@ -273,8 +277,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -391,7 +395,7 @@ public function archiveRequest($object_type, $object_id, $to_object_type, $to_ob } 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 createWithHttpInfo($object_type, $object_id, $to_object_type, $t 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 ); } ); @@ -735,7 +743,7 @@ public function createRequest($object_type, $object_id, $to_object_type, $to_obj if (isset($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($association_spec)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($association_spec), JSON_THROW_ON_ERROR); } else { $httpBody = $association_spec; } @@ -756,7 +764,7 @@ public function createRequest($object_type, $object_id, $to_object_type, $to_obj } 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); @@ -834,13 +842,16 @@ public function createDefaultWithHttpInfo($from_object_type, $from_object_id, $t 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(), @@ -975,8 +986,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)', @@ -984,8 +996,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1102,7 +1114,7 @@ public function createDefaultRequest($from_object_type, $from_object_id, $to_obj } 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); @@ -1182,13 +1194,16 @@ public function getPageWithHttpInfo($object_type, $object_id, $to_object_type, $ 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(), @@ -1325,8 +1340,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)', @@ -1334,8 +1350,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1458,7 +1474,7 @@ public function getPageRequest($object_type, $object_id, $to_object_type, $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); diff --git a/codegen/Crm/Associations/V4/Api/BatchApi.php b/codegen/Crm/Associations/V4/Api/BatchApi.php index c93d01ba3..3d97c025d 100644 --- a/codegen/Crm/Associations/V4/Api/BatchApi.php +++ b/codegen/Crm/Associations/V4/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\Associations\V4\ApiException; @@ -179,13 +179,16 @@ public function archiveWithHttpInfo($from_object_type, $to_object_type, $batch_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(), @@ -263,8 +266,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)', @@ -272,8 +276,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -352,7 +356,7 @@ public function archiveRequest($from_object_type, $to_object_type, $batch_input_ if (isset($batch_input_public_association_multi_archive)) { 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_multi_archive)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_multi_archive), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association_multi_archive; } @@ -373,7 +377,7 @@ public function archiveRequest($from_object_type, $to_object_type, $batch_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); @@ -448,13 +452,16 @@ public function archiveLabelsWithHttpInfo($from_object_type, $to_object_type, $b 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(), @@ -532,8 +539,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)', @@ -541,8 +549,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -621,7 +629,7 @@ public function archiveLabelsRequest($from_object_type, $to_object_type, $batch_ if (isset($batch_input_public_association_multi_post)) { 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_multi_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_multi_post), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association_multi_post; } @@ -642,7 +650,7 @@ public function archiveLabelsRequest($from_object_type, $to_object_type, $batch_ } 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); @@ -718,13 +726,16 @@ public function createWithHttpInfo($from_object_type, $to_object_type, $batch_in 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 ); } ); @@ -960,7 +972,7 @@ public function createRequest($from_object_type, $to_object_type, $batch_input_p if (isset($batch_input_public_association_multi_post)) { 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_multi_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_association_multi_post), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_association_multi_post; } @@ -981,7 +993,7 @@ public function createRequest($from_object_type, $to_object_type, $batch_input_p } 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 createDefaultWithHttpInfo($from_object_type, $to_object_type, $b 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(), @@ -1196,8 +1211,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)', @@ -1205,8 +1221,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1285,7 +1301,7 @@ public function createDefaultRequest($from_object_type, $to_object_type, $batch_ if (isset($batch_input_public_default_association_multi_post)) { 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_default_association_multi_post)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_default_association_multi_post), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_default_association_multi_post; } @@ -1306,7 +1322,7 @@ public function createDefaultRequest($from_object_type, $to_object_type, $batch_ } 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); @@ -1382,13 +1398,16 @@ public function getPageWithHttpInfo($from_object_type, $to_object_type, $batch_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(), @@ -1535,8 +1554,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)', @@ -1544,8 +1564,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1624,7 +1644,7 @@ public function getPageRequest($from_object_type, $to_object_type, $batch_input_ if (isset($batch_input_public_fetch_associations_batch_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_fetch_associations_batch_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_fetch_associations_batch_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_fetch_associations_batch_request; } @@ -1645,7 +1665,7 @@ public function getPageRequest($from_object_type, $to_object_type, $batch_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/Associations/V4/Api/ReportApi.php b/codegen/Crm/Associations/V4/Api/ReportApi.php index c0da4fae9..d4094e76e 100644 --- a/codegen/Crm/Associations/V4/Api/ReportApi.php +++ b/codegen/Crm/Associations/V4/Api/ReportApi.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\ApiException; @@ -164,13 +164,16 @@ public function requestWithHttpInfo($user_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(), @@ -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 ); } ); @@ -378,7 +382,7 @@ public function requestRequest($user_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); 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/Commerce/Invoices/Api/BasicApi.php b/codegen/Crm/Commerce/Invoices/Api/BasicApi.php index 8eb4ae450..00c4c19c1 100644 --- a/codegen/Crm/Commerce/Invoices/Api/BasicApi.php +++ b/codegen/Crm/Commerce/Invoices/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\Commerce\Invoices\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($invoice_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($invoice_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($invoice_id, $properties = null, $properties 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($invoice_id, $properties = null, $properties_with } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($invoice_id, $simple_public_object_input, $id 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($invoice_id, $simple_public_object_input, $id_prop 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($invoice_id, $simple_public_object_input, $id_prop } 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/Commerce/Invoices/Api/BatchApi.php b/codegen/Crm/Commerce/Invoices/Api/BatchApi.php index f86675039..2357da48b 100644 --- a/codegen/Crm/Commerce/Invoices/Api/BatchApi.php +++ b/codegen/Crm/Commerce/Invoices/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\Commerce\Invoices\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Commerce/Invoices/Api/SearchApi.php b/codegen/Crm/Commerce/Invoices/Api/SearchApi.php index cbbe05a39..3a8eeeb69 100644 --- a/codegen/Crm/Commerce/Invoices/Api/SearchApi.php +++ b/codegen/Crm/Commerce/Invoices/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\Commerce\Invoices\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Companies/Api/BasicApi.php b/codegen/Crm/Companies/Api/BasicApi.php index 500cb6364..c179806eb 100644 --- a/codegen/Crm/Companies/Api/BasicApi.php +++ b/codegen/Crm/Companies/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\Companies\ApiException; @@ -178,13 +178,16 @@ public function archiveWithHttpInfo($company_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(), @@ -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 ); } ); @@ -340,7 +344,7 @@ public function archiveRequest($company_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); @@ -412,13 +416,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -545,8 +552,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)', @@ -554,8 +562,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -602,7 +610,7 @@ public function createRequest($simple_public_object_input_for_create, string $co 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; } @@ -623,7 +631,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -705,13 +713,16 @@ public function getByIdWithHttpInfo($company_id, $properties = null, $properties 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(), @@ -850,8 +861,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)', @@ -859,8 +871,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -987,7 +999,7 @@ public function getByIdRequest($company_id, $properties = null, $properties_with } 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); @@ -1069,13 +1081,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1214,8 +1229,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)', @@ -1223,8 +1239,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1343,7 +1359,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1415,13 +1431,16 @@ public function mergeWithHttpInfo($public_merge_input, 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(), @@ -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 ); } ); @@ -1607,7 +1627,7 @@ public function mergeRequest($public_merge_input, string $contentType = self::co if (isset($public_merge_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($public_merge_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_merge_input), JSON_THROW_ON_ERROR); } else { $httpBody = $public_merge_input; } @@ -1628,7 +1648,7 @@ public function mergeRequest($public_merge_input, 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); @@ -1704,13 +1724,16 @@ public function updateWithHttpInfo($company_id, $simple_public_object_input, $id 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(), @@ -1843,8 +1866,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)', @@ -1852,8 +1876,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1930,7 +1954,7 @@ public function updateRequest($company_id, $simple_public_object_input, $id_prop 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; } @@ -1951,7 +1975,7 @@ public function updateRequest($company_id, $simple_public_object_input, $id_prop } 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/Companies/Api/BatchApi.php b/codegen/Crm/Companies/Api/BatchApi.php index ae49fa8fb..3089387bd 100644 --- a/codegen/Crm/Companies/Api/BatchApi.php +++ b/codegen/Crm/Companies/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\Companies\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Companies/Api/SearchApi.php b/codegen/Crm/Companies/Api/SearchApi.php index 3d47a93d4..884e7dde2 100644 --- a/codegen/Crm/Companies/Api/SearchApi.php +++ b/codegen/Crm/Companies/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\Companies\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Contacts/Api/BasicApi.php b/codegen/Crm/Contacts/Api/BasicApi.php index 0416e63b3..4ee7e2dab 100644 --- a/codegen/Crm/Contacts/Api/BasicApi.php +++ b/codegen/Crm/Contacts/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\Contacts\ApiException; @@ -181,13 +181,16 @@ public function archiveWithHttpInfo($contact_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(), @@ -261,8 +264,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)', @@ -270,8 +274,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -343,7 +347,7 @@ public function archiveRequest($contact_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); @@ -415,13 +419,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -550,8 +557,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)', @@ -559,8 +567,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -607,7 +615,7 @@ public function createRequest($simple_public_object_input_for_create, string $co 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; } @@ -628,7 +636,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -710,13 +718,16 @@ public function getByIdWithHttpInfo($contact_id, $properties = null, $properties 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(), @@ -855,8 +866,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)', @@ -864,8 +876,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -992,7 +1004,7 @@ public function getByIdRequest($contact_id, $properties = null, $properties_with } 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); @@ -1074,13 +1086,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1219,8 +1234,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)', @@ -1228,8 +1244,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1348,7 +1364,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1420,13 +1436,16 @@ public function mergeWithHttpInfo($public_merge_input, 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(), @@ -1555,8 +1574,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)', @@ -1564,8 +1584,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1612,7 +1632,7 @@ public function mergeRequest($public_merge_input, string $contentType = self::co if (isset($public_merge_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($public_merge_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_merge_input), JSON_THROW_ON_ERROR); } else { $httpBody = $public_merge_input; } @@ -1633,7 +1653,7 @@ public function mergeRequest($public_merge_input, 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); @@ -1704,13 +1724,16 @@ public function purgeWithHttpInfo($public_gdpr_delete_input, 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(), @@ -1784,8 +1807,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)', @@ -1793,8 +1817,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1841,7 +1865,7 @@ public function purgeRequest($public_gdpr_delete_input, string $contentType = se if (isset($public_gdpr_delete_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($public_gdpr_delete_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_gdpr_delete_input), JSON_THROW_ON_ERROR); } else { $httpBody = $public_gdpr_delete_input; } @@ -1862,7 +1886,7 @@ public function purgeRequest($public_gdpr_delete_input, string $contentType = se } 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); @@ -1938,13 +1962,16 @@ public function updateWithHttpInfo($contact_id, $simple_public_object_input, $id 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(), @@ -2077,8 +2104,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)', @@ -2086,8 +2114,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2164,7 +2192,7 @@ public function updateRequest($contact_id, $simple_public_object_input, $id_prop 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; } @@ -2185,7 +2213,7 @@ public function updateRequest($contact_id, $simple_public_object_input, $id_prop } 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/Contacts/Api/BatchApi.php b/codegen/Crm/Contacts/Api/BatchApi.php index 143ecde8d..37f83ea53 100644 --- a/codegen/Crm/Contacts/Api/BatchApi.php +++ b/codegen/Crm/Contacts/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\Contacts\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Contacts/Api/SearchApi.php b/codegen/Crm/Contacts/Api/SearchApi.php index ca7c229d4..27e7f16b9 100644 --- a/codegen/Crm/Contacts/Api/SearchApi.php +++ b/codegen/Crm/Contacts/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\Contacts\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Deals/Api/BasicApi.php b/codegen/Crm/Deals/Api/BasicApi.php index 8f7cd817a..e688cb5e6 100644 --- a/codegen/Crm/Deals/Api/BasicApi.php +++ b/codegen/Crm/Deals/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\Deals\ApiException; @@ -178,13 +178,16 @@ public function archiveWithHttpInfo($deal_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 ); } ); @@ -340,7 +344,7 @@ public function archiveRequest($deal_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); @@ -412,13 +416,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -547,8 +554,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)', @@ -556,8 +564,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -604,7 +612,7 @@ public function createRequest($simple_public_object_input_for_create, string $co 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; } @@ -625,7 +633,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -707,13 +715,16 @@ public function getByIdWithHttpInfo($deal_id, $properties = null, $properties_wi 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(), @@ -852,8 +863,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)', @@ -861,8 +873,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -989,7 +1001,7 @@ public function getByIdRequest($deal_id, $properties = null, $properties_with_hi } 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); @@ -1071,13 +1083,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1216,8 +1231,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)', @@ -1225,8 +1241,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($limit = 10, $after = null, $properties = 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); @@ -1417,13 +1433,16 @@ public function mergeWithHttpInfo($public_merge_input, 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(), @@ -1552,8 +1571,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)', @@ -1561,8 +1581,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1609,7 +1629,7 @@ public function mergeRequest($public_merge_input, string $contentType = self::co if (isset($public_merge_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($public_merge_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_merge_input), JSON_THROW_ON_ERROR); } else { $httpBody = $public_merge_input; } @@ -1630,7 +1650,7 @@ public function mergeRequest($public_merge_input, 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); @@ -1706,13 +1726,16 @@ public function updateWithHttpInfo($deal_id, $simple_public_object_input, $id_pr 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(), @@ -1845,8 +1868,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)', @@ -1854,8 +1878,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1932,7 +1956,7 @@ public function updateRequest($deal_id, $simple_public_object_input, $id_propert 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; } @@ -1953,7 +1977,7 @@ public function updateRequest($deal_id, $simple_public_object_input, $id_propert } 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/Deals/Api/BatchApi.php b/codegen/Crm/Deals/Api/BatchApi.php index 508e75550..499d057eb 100644 --- a/codegen/Crm/Deals/Api/BatchApi.php +++ b/codegen/Crm/Deals/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\Deals\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Deals/Api/SearchApi.php b/codegen/Crm/Deals/Api/SearchApi.php index 63fc703c4..feccddabc 100644 --- a/codegen/Crm/Deals/Api/SearchApi.php +++ b/codegen/Crm/Deals/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\Deals\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/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/LineItems/Api/BasicApi.php b/codegen/Crm/LineItems/Api/BasicApi.php index 1e65e5463..7fb0be802 100644 --- a/codegen/Crm/LineItems/Api/BasicApi.php +++ b/codegen/Crm/LineItems/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\LineItems\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($line_item_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($line_item_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($line_item_id, $properties = null, $properti 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($line_item_id, $properties = null, $properties_wi } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($line_item_id, $simple_public_object_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($line_item_id, $simple_public_object_input, $id_pr 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($line_item_id, $simple_public_object_input, $id_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); diff --git a/codegen/Crm/LineItems/Api/BatchApi.php b/codegen/Crm/LineItems/Api/BatchApi.php index b29e3aea4..53e871d5a 100644 --- a/codegen/Crm/LineItems/Api/BatchApi.php +++ b/codegen/Crm/LineItems/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\LineItems\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/LineItems/Api/SearchApi.php b/codegen/Crm/LineItems/Api/SearchApi.php index a74306352..395789591 100644 --- a/codegen/Crm/LineItems/Api/SearchApi.php +++ b/codegen/Crm/LineItems/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\LineItems\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/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/Objects/Calls/Api/BasicApi.php b/codegen/Crm/Objects/Calls/Api/BasicApi.php index 52d324545..5c48d8b10 100644 --- a/codegen/Crm/Objects/Calls/Api/BasicApi.php +++ b/codegen/Crm/Objects/Calls/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\Calls\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($call_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($call_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($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($call_id, $properties = null, $properties_wi 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($call_id, $properties = null, $properties_with_hi } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($call_id, $simple_public_object_input, $id_pr 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($call_id, $simple_public_object_input, $id_propert 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($call_id, $simple_public_object_input, $id_propert } 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/Calls/Api/BatchApi.php b/codegen/Crm/Objects/Calls/Api/BatchApi.php index db38440a3..647468e8a 100644 --- a/codegen/Crm/Objects/Calls/Api/BatchApi.php +++ b/codegen/Crm/Objects/Calls/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\Calls\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Calls/Api/SearchApi.php b/codegen/Crm/Objects/Calls/Api/SearchApi.php index 1c9736663..e8b6d7080 100644 --- a/codegen/Crm/Objects/Calls/Api/SearchApi.php +++ b/codegen/Crm/Objects/Calls/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\Calls\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Communications/Api/BasicApi.php b/codegen/Crm/Objects/Communications/Api/BasicApi.php index 3da5f7279..450562358 100644 --- a/codegen/Crm/Objects/Communications/Api/BasicApi.php +++ b/codegen/Crm/Objects/Communications/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\Communications\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($communication_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($communication_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($communication_id, $properties = null, $prop 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($communication_id, $properties = null, $propertie } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($communication_id, $simple_public_object_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($communication_id, $simple_public_object_input, $i 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($communication_id, $simple_public_object_input, $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); diff --git a/codegen/Crm/Objects/Communications/Api/BatchApi.php b/codegen/Crm/Objects/Communications/Api/BatchApi.php index 53dbc9ad5..43a2c4f74 100644 --- a/codegen/Crm/Objects/Communications/Api/BatchApi.php +++ b/codegen/Crm/Objects/Communications/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\Communications\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Communications/Api/SearchApi.php b/codegen/Crm/Objects/Communications/Api/SearchApi.php index 841a915b9..2c93c9819 100644 --- a/codegen/Crm/Objects/Communications/Api/SearchApi.php +++ b/codegen/Crm/Objects/Communications/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\Communications\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/DealSplits/Api/BatchApi.php b/codegen/Crm/Objects/DealSplits/Api/BatchApi.php index b20d24b24..942f07d33 100644 --- a/codegen/Crm/Objects/DealSplits/Api/BatchApi.php +++ b/codegen/Crm/Objects/DealSplits/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\DealSplits\ApiException; @@ -167,13 +167,16 @@ public function readWithHttpInfo($batch_input_public_object_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(), @@ -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 ); } ); @@ -373,7 +377,7 @@ public function readRequest($batch_input_public_object_id, string $contentType = if (isset($batch_input_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_public_object_id)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_public_object_id), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_public_object_id; } @@ -394,7 +398,7 @@ public function readRequest($batch_input_public_object_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); @@ -466,13 +470,16 @@ public function upsertWithHttpInfo($public_deal_splits_batch_create_request, 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(), @@ -615,8 +622,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)', @@ -624,8 +632,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -672,7 +680,7 @@ public function upsertRequest($public_deal_splits_batch_create_request, string $ if (isset($public_deal_splits_batch_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_deal_splits_batch_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_deal_splits_batch_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $public_deal_splits_batch_create_request; } @@ -693,7 +701,7 @@ public function upsertRequest($public_deal_splits_batch_create_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/Objects/Emails/Api/BasicApi.php b/codegen/Crm/Objects/Emails/Api/BasicApi.php index 216affef3..1cd625f7a 100644 --- a/codegen/Crm/Objects/Emails/Api/BasicApi.php +++ b/codegen/Crm/Objects/Emails/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\Emails\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($email_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($email_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($email_id, $properties = null, $properties_w 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($email_id, $properties = null, $properties_with_h } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($email_id, $simple_public_object_input, $id_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($email_id, $simple_public_object_input, $id_proper 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($email_id, $simple_public_object_input, $id_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); diff --git a/codegen/Crm/Objects/Emails/Api/BatchApi.php b/codegen/Crm/Objects/Emails/Api/BatchApi.php index 40ef30897..ab22158d2 100644 --- a/codegen/Crm/Objects/Emails/Api/BatchApi.php +++ b/codegen/Crm/Objects/Emails/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\Emails\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Emails/Api/SearchApi.php b/codegen/Crm/Objects/Emails/Api/SearchApi.php index 6e98f0434..66e45dfbe 100644 --- a/codegen/Crm/Objects/Emails/Api/SearchApi.php +++ b/codegen/Crm/Objects/Emails/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\Emails\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/FeedbackSubmissions/Api/BasicApi.php b/codegen/Crm/Objects/FeedbackSubmissions/Api/BasicApi.php index 7fbd2e20e..19d4a9645 100644 --- a/codegen/Crm/Objects/FeedbackSubmissions/Api/BasicApi.php +++ b/codegen/Crm/Objects/FeedbackSubmissions/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\FeedbackSubmissions\ApiException; @@ -177,13 +177,16 @@ public function getByIdWithHttpInfo($feedback_submission_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(), @@ -322,8 +325,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)', @@ -331,8 +335,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -459,7 +463,7 @@ public function getByIdRequest($feedback_submission_id, $properties = null, $pro } 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); @@ -541,13 +545,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -686,8 +693,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)', @@ -695,8 +703,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -815,7 +823,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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/Objects/FeedbackSubmissions/Api/BatchApi.php b/codegen/Crm/Objects/FeedbackSubmissions/Api/BatchApi.php index b3eed3d62..3bf3f7531 100644 --- a/codegen/Crm/Objects/FeedbackSubmissions/Api/BatchApi.php +++ b/codegen/Crm/Objects/FeedbackSubmissions/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\FeedbackSubmissions\ApiException; @@ -166,13 +166,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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 ); } ); @@ -371,7 +375,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -392,7 +396,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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/FeedbackSubmissions/Api/SearchApi.php b/codegen/Crm/Objects/FeedbackSubmissions/Api/SearchApi.php index 4da349bde..4a7c7ba13 100644 --- a/codegen/Crm/Objects/FeedbackSubmissions/Api/SearchApi.php +++ b/codegen/Crm/Objects/FeedbackSubmissions/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\FeedbackSubmissions\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Goals/Api/BasicApi.php b/codegen/Crm/Objects/Goals/Api/BasicApi.php index 86493b9cc..47df3cc43 100644 --- a/codegen/Crm/Objects/Goals/Api/BasicApi.php +++ b/codegen/Crm/Objects/Goals/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\Goals\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($goal_target_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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($goal_target_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($goal_target_id, $properties = null, $proper 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($goal_target_id, $properties = null, $properties_ } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($goal_target_id, $simple_public_object_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($goal_target_id, $simple_public_object_input, $id_ 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($goal_target_id, $simple_public_object_input, $id_ } 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/Goals/Api/BatchApi.php b/codegen/Crm/Objects/Goals/Api/BatchApi.php index 254a92e57..4182852ec 100644 --- a/codegen/Crm/Objects/Goals/Api/BatchApi.php +++ b/codegen/Crm/Objects/Goals/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\Goals\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Goals/Api/SearchApi.php b/codegen/Crm/Objects/Goals/Api/SearchApi.php index 5a51c6058..a653ef8fd 100644 --- a/codegen/Crm/Objects/Goals/Api/SearchApi.php +++ b/codegen/Crm/Objects/Goals/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\Goals\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Leads/Api/BasicApi.php b/codegen/Crm/Objects/Leads/Api/BasicApi.php index 6cbc0c232..79947ed83 100644 --- a/codegen/Crm/Objects/Leads/Api/BasicApi.php +++ b/codegen/Crm/Objects/Leads/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\Leads\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($leads_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($leads_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($leads_id, $properties = null, $properties_w 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($leads_id, $properties = null, $properties_with_h } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($leads_id, $simple_public_object_input, $id_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($leads_id, $simple_public_object_input, $id_proper 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($leads_id, $simple_public_object_input, $id_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); diff --git a/codegen/Crm/Objects/Leads/Api/BatchApi.php b/codegen/Crm/Objects/Leads/Api/BatchApi.php index 8c9fb4a88..f5d086870 100644 --- a/codegen/Crm/Objects/Leads/Api/BatchApi.php +++ b/codegen/Crm/Objects/Leads/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\Leads\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Leads/Api/SearchApi.php b/codegen/Crm/Objects/Leads/Api/SearchApi.php index 6597b3407..6e8e9c6f8 100644 --- a/codegen/Crm/Objects/Leads/Api/SearchApi.php +++ b/codegen/Crm/Objects/Leads/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\Leads\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Meetings/Api/BasicApi.php b/codegen/Crm/Objects/Meetings/Api/BasicApi.php index 5a00322b5..ea7773602 100644 --- a/codegen/Crm/Objects/Meetings/Api/BasicApi.php +++ b/codegen/Crm/Objects/Meetings/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\Meetings\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($meeting_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($meeting_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($meeting_id, $properties = null, $properties 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($meeting_id, $properties = null, $properties_with } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($meeting_id, $simple_public_object_input, $id 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($meeting_id, $simple_public_object_input, $id_prop 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($meeting_id, $simple_public_object_input, $id_prop } 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/Meetings/Api/BatchApi.php b/codegen/Crm/Objects/Meetings/Api/BatchApi.php index 39c8425a2..22c1b1ad2 100644 --- a/codegen/Crm/Objects/Meetings/Api/BatchApi.php +++ b/codegen/Crm/Objects/Meetings/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\Meetings\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Meetings/Api/SearchApi.php b/codegen/Crm/Objects/Meetings/Api/SearchApi.php index 60d6a6e80..e4d831022 100644 --- a/codegen/Crm/Objects/Meetings/Api/SearchApi.php +++ b/codegen/Crm/Objects/Meetings/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\Meetings\ApiException; @@ -160,13 +160,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -291,8 +294,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)', @@ -300,8 +304,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -348,7 +352,7 @@ public function doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -369,7 +373,7 @@ public function doSearchRequest($public_object_search_request, string $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/Notes/Api/BasicApi.php b/codegen/Crm/Objects/Notes/Api/BasicApi.php index 76839a766..a0deaef21 100644 --- a/codegen/Crm/Objects/Notes/Api/BasicApi.php +++ b/codegen/Crm/Objects/Notes/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\Notes\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($note_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($note_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($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($note_id, $properties = null, $properties_wi 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($note_id, $properties = null, $properties_with_hi } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($note_id, $simple_public_object_input, $id_pr 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($note_id, $simple_public_object_input, $id_propert 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($note_id, $simple_public_object_input, $id_propert } 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/Notes/Api/BatchApi.php b/codegen/Crm/Objects/Notes/Api/BatchApi.php index b046e26c2..eb9e0fbfb 100644 --- a/codegen/Crm/Objects/Notes/Api/BatchApi.php +++ b/codegen/Crm/Objects/Notes/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\Notes\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Notes/Api/SearchApi.php b/codegen/Crm/Objects/Notes/Api/SearchApi.php index c5f8cc7d9..2e7b1efd4 100644 --- a/codegen/Crm/Objects/Notes/Api/SearchApi.php +++ b/codegen/Crm/Objects/Notes/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\Notes\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/PostalMail/Api/BasicApi.php b/codegen/Crm/Objects/PostalMail/Api/BasicApi.php index 64d94e5c9..98bccdb29 100644 --- a/codegen/Crm/Objects/PostalMail/Api/BasicApi.php +++ b/codegen/Crm/Objects/PostalMail/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\PostalMail\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($postal_mail_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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($postal_mail_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($postal_mail_id, $properties = null, $proper 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($postal_mail_id, $properties = null, $properties_ } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($postal_mail_id, $simple_public_object_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($postal_mail_id, $simple_public_object_input, $id_ 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($postal_mail_id, $simple_public_object_input, $id_ } 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/PostalMail/Api/BatchApi.php b/codegen/Crm/Objects/PostalMail/Api/BatchApi.php index a53a90526..6b9d5ca60 100644 --- a/codegen/Crm/Objects/PostalMail/Api/BatchApi.php +++ b/codegen/Crm/Objects/PostalMail/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\PostalMail\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/PostalMail/Api/SearchApi.php b/codegen/Crm/Objects/PostalMail/Api/SearchApi.php index 0abb7865d..e9a64d207 100644 --- a/codegen/Crm/Objects/PostalMail/Api/SearchApi.php +++ b/codegen/Crm/Objects/PostalMail/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\PostalMail\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Tasks/Api/BasicApi.php b/codegen/Crm/Objects/Tasks/Api/BasicApi.php index 219f288d6..8b4a18faf 100644 --- a/codegen/Crm/Objects/Tasks/Api/BasicApi.php +++ b/codegen/Crm/Objects/Tasks/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\Tasks\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($task_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($task_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($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($task_id, $properties = null, $properties_wi 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($task_id, $properties = null, $properties_with_hi } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($task_id, $simple_public_object_input, $id_pr 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($task_id, $simple_public_object_input, $id_propert 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($task_id, $simple_public_object_input, $id_propert } 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/Tasks/Api/BatchApi.php b/codegen/Crm/Objects/Tasks/Api/BatchApi.php index 24832fc8d..3224974f1 100644 --- a/codegen/Crm/Objects/Tasks/Api/BatchApi.php +++ b/codegen/Crm/Objects/Tasks/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\Tasks\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Tasks/Api/SearchApi.php b/codegen/Crm/Objects/Tasks/Api/SearchApi.php index a63519bd9..0ed5c75c2 100644 --- a/codegen/Crm/Objects/Tasks/Api/SearchApi.php +++ b/codegen/Crm/Objects/Tasks/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\Tasks\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Taxes/Api/BasicApi.php b/codegen/Crm/Objects/Taxes/Api/BasicApi.php index d00651530..36aa1015f 100644 --- a/codegen/Crm/Objects/Taxes/Api/BasicApi.php +++ b/codegen/Crm/Objects/Taxes/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\Taxes\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($tax_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($tax_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($tax_id, $properties = null, $properties_wit 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($tax_id, $properties = null, $properties_with_his } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($tax_id, $simple_public_object_input, $id_pro 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($tax_id, $simple_public_object_input, $id_property 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($tax_id, $simple_public_object_input, $id_property } 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/Taxes/Api/BatchApi.php b/codegen/Crm/Objects/Taxes/Api/BatchApi.php index 772683708..9af6d0c30 100644 --- a/codegen/Crm/Objects/Taxes/Api/BatchApi.php +++ b/codegen/Crm/Objects/Taxes/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\Taxes\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Taxes/Api/SearchApi.php b/codegen/Crm/Objects/Taxes/Api/SearchApi.php index efa8d9429..271236864 100644 --- a/codegen/Crm/Objects/Taxes/Api/SearchApi.php +++ b/codegen/Crm/Objects/Taxes/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\Taxes\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/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/Products/Api/BasicApi.php b/codegen/Crm/Products/Api/BasicApi.php index 1fad87863..805afb890 100644 --- a/codegen/Crm/Products/Api/BasicApi.php +++ b/codegen/Crm/Products/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\Products\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($product_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($product_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($product_id, $properties = null, $properties 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($product_id, $properties = null, $properties_with } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($product_id, $simple_public_object_input, $id 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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($product_id, $simple_public_object_input, $id_prop 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($product_id, $simple_public_object_input, $id_prop } 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/Products/Api/BatchApi.php b/codegen/Crm/Products/Api/BatchApi.php index 105ba064f..6b144fdd3 100644 --- a/codegen/Crm/Products/Api/BatchApi.php +++ b/codegen/Crm/Products/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\Products\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Products/Api/SearchApi.php b/codegen/Crm/Products/Api/SearchApi.php index 56d0fd04e..430bfbef2 100644 --- a/codegen/Crm/Products/Api/SearchApi.php +++ b/codegen/Crm/Products/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\Products\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/Properties/Api/BatchApi.php b/codegen/Crm/Properties/Api/BatchApi.php index 02d74d2f5..276918021 100644 --- a/codegen/Crm/Properties/Api/BatchApi.php +++ b/codegen/Crm/Properties/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\Properties\ApiException; @@ -171,13 +171,16 @@ public function archiveWithHttpInfo($object_type, $batch_input_property_name, 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(), @@ -253,8 +256,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)', @@ -262,8 +266,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -326,7 +330,7 @@ public function archiveRequest($object_type, $batch_input_property_name, string if (isset($batch_input_property_name)) { 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_property_name)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_property_name), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_property_name; } @@ -347,7 +351,7 @@ public function archiveRequest($object_type, $batch_input_property_name, 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); @@ -421,13 +425,16 @@ public function createWithHttpInfo($object_type, $batch_input_property_create, 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(), @@ -572,8 +579,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)', @@ -581,8 +589,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -645,7 +653,7 @@ public function createRequest($object_type, $batch_input_property_create, string if (isset($batch_input_property_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_property_create)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_property_create), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_property_create; } @@ -666,7 +674,7 @@ public function createRequest($object_type, $batch_input_property_create, 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); @@ -742,13 +750,16 @@ public function readWithHttpInfo($object_type, $batch_read_input_property_name, 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(), @@ -895,8 +906,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)', @@ -904,8 +916,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -979,7 +991,7 @@ public function readRequest($object_type, $batch_read_input_property_name, $loca if (isset($batch_read_input_property_name)) { 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_property_name)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_read_input_property_name), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_read_input_property_name; } @@ -1000,7 +1012,7 @@ public function readRequest($object_type, $batch_read_input_property_name, $loca } 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/CoreApi.php b/codegen/Crm/Properties/Api/CoreApi.php index 73b498730..964b16cdd 100644 --- a/codegen/Crm/Properties/Api/CoreApi.php +++ b/codegen/Crm/Properties/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\Properties\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($object_type, $property_name, 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(), @@ -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, $property_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_create, 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(), @@ -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_create, string $contentTyp if (isset($property_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_create)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($property_create), JSON_THROW_ON_ERROR); } else { $httpBody = $property_create; } @@ -659,7 +667,7 @@ public function createRequest($object_type, $property_create, 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); @@ -739,13 +747,16 @@ public function getAllWithHttpInfo($object_type, $archived = false, $properties 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(), @@ -882,8 +893,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)', @@ -891,8 +903,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1005,7 +1017,7 @@ public function getAllRequest($object_type, $archived = false, $properties = nul } 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); @@ -1087,13 +1099,16 @@ public function getByNameWithHttpInfo($object_type, $property_name, $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(), @@ -1232,8 +1247,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)', @@ -1241,8 +1257,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1371,7 +1387,7 @@ public function getByNameRequest($object_type, $property_name, $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); @@ -1447,13 +1463,16 @@ public function updateWithHttpInfo($object_type, $property_name, $property_updat 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(), @@ -1586,8 +1605,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)', @@ -1595,8 +1615,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1675,7 +1695,7 @@ public function updateRequest($object_type, $property_name, $property_update, st if (isset($property_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_update)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($property_update), JSON_THROW_ON_ERROR); } else { $httpBody = $property_update; } @@ -1696,7 +1716,7 @@ public function updateRequest($object_type, $property_name, $property_update, 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); 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/Quotes/Api/BasicApi.php b/codegen/Crm/Quotes/Api/BasicApi.php index 6f224355c..f76d89d87 100644 --- a/codegen/Crm/Quotes/Api/BasicApi.php +++ b/codegen/Crm/Quotes/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\Quotes\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($quote_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(), @@ -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 ); } ); @@ -337,7 +341,7 @@ public function archiveRequest($quote_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); @@ -409,13 +413,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -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($simple_public_object_input_for_create, string $co 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; } @@ -622,7 +630,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -704,13 +712,16 @@ public function getByIdWithHttpInfo($quote_id, $properties = null, $properties_w 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(), @@ -849,8 +860,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)', @@ -858,8 +870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -986,7 +998,7 @@ public function getByIdRequest($quote_id, $properties = null, $properties_with_h } 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); @@ -1068,13 +1080,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1213,8 +1228,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)', @@ -1222,8 +1238,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1342,7 +1358,7 @@ public function getPageRequest($limit = 10, $after = null, $properties = 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); @@ -1418,13 +1434,16 @@ public function updateWithHttpInfo($quote_id, $simple_public_object_input, $id_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(), @@ -1557,8 +1576,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)', @@ -1566,8 +1586,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1644,7 +1664,7 @@ public function updateRequest($quote_id, $simple_public_object_input, $id_proper 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; } @@ -1665,7 +1685,7 @@ public function updateRequest($quote_id, $simple_public_object_input, $id_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); diff --git a/codegen/Crm/Quotes/Api/BatchApi.php b/codegen/Crm/Quotes/Api/BatchApi.php index 8d1b2de56..85437e578 100644 --- a/codegen/Crm/Quotes/Api/BatchApi.php +++ b/codegen/Crm/Quotes/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\Quotes\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Quotes/Api/SearchApi.php b/codegen/Crm/Quotes/Api/SearchApi.php index c3e06c67c..32ded8b6a 100644 --- a/codegen/Crm/Quotes/Api/SearchApi.php +++ b/codegen/Crm/Quotes/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\Quotes\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/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/Tickets/Api/BasicApi.php b/codegen/Crm/Tickets/Api/BasicApi.php index a9dab79d2..ec1806340 100644 --- a/codegen/Crm/Tickets/Api/BasicApi.php +++ b/codegen/Crm/Tickets/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\Tickets\ApiException; @@ -178,13 +178,16 @@ public function archiveWithHttpInfo($ticket_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(), @@ -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 ); } ); @@ -340,7 +344,7 @@ public function archiveRequest($ticket_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); @@ -412,13 +416,16 @@ public function createWithHttpInfo($simple_public_object_input_for_create, 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(), @@ -547,8 +554,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)', @@ -556,8 +564,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -604,7 +612,7 @@ public function createRequest($simple_public_object_input_for_create, string $co 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; } @@ -625,7 +633,7 @@ public function createRequest($simple_public_object_input_for_create, 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); @@ -707,13 +715,16 @@ public function getByIdWithHttpInfo($ticket_id, $properties = null, $properties_ 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(), @@ -852,8 +863,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)', @@ -861,8 +873,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -989,7 +1001,7 @@ public function getByIdRequest($ticket_id, $properties = null, $properties_with_ } 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); @@ -1071,13 +1083,16 @@ public function getPageWithHttpInfo($limit = 10, $after = null, $properties = 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(), @@ -1216,8 +1231,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)', @@ -1225,8 +1241,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($limit = 10, $after = null, $properties = 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); @@ -1417,13 +1433,16 @@ public function mergeWithHttpInfo($public_merge_input, 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(), @@ -1552,8 +1571,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)', @@ -1561,8 +1581,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1609,7 +1629,7 @@ public function mergeRequest($public_merge_input, string $contentType = self::co if (isset($public_merge_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($public_merge_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_merge_input), JSON_THROW_ON_ERROR); } else { $httpBody = $public_merge_input; } @@ -1630,7 +1650,7 @@ public function mergeRequest($public_merge_input, 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); @@ -1706,13 +1726,16 @@ public function updateWithHttpInfo($ticket_id, $simple_public_object_input, $id_ 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(), @@ -1845,8 +1868,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)', @@ -1854,8 +1878,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1932,7 +1956,7 @@ public function updateRequest($ticket_id, $simple_public_object_input, $id_prope 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; } @@ -1953,7 +1977,7 @@ public function updateRequest($ticket_id, $simple_public_object_input, $id_prope } 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/Tickets/Api/BatchApi.php b/codegen/Crm/Tickets/Api/BatchApi.php index b79e53412..ca85e875a 100644 --- a/codegen/Crm/Tickets/Api/BatchApi.php +++ b/codegen/Crm/Tickets/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\Tickets\ApiException; @@ -175,13 +175,16 @@ public function archiveWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -312,7 +316,7 @@ public function archiveRequest($batch_input_simple_public_object_id, string $con 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; } @@ -333,7 +337,7 @@ public function archiveRequest($batch_input_simple_public_object_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); @@ -405,13 +409,16 @@ public function createWithHttpInfo($batch_input_simple_public_object_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(), @@ -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 ); } ); @@ -597,7 +605,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ 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; } @@ -618,7 +626,7 @@ public function createRequest($batch_input_simple_public_object_batch_input_for_ } 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); @@ -692,13 +700,16 @@ public function readWithHttpInfo($batch_read_input_simple_public_object_id, $arc 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(), @@ -829,8 +840,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)', @@ -838,8 +850,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived 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; } @@ -918,7 +930,7 @@ public function readRequest($batch_read_input_simple_public_object_id, $archived } 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); @@ -990,13 +1002,16 @@ public function updateWithHttpInfo($batch_input_simple_public_object_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(), @@ -1125,8 +1140,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)', @@ -1134,8 +1150,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1182,7 +1198,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, str 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; } @@ -1203,7 +1219,7 @@ public function updateRequest($batch_input_simple_public_object_batch_input, 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); @@ -1275,13 +1291,16 @@ public function upsertWithHttpInfo($batch_input_simple_public_object_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(), @@ -1410,8 +1429,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)', @@ -1419,8 +1439,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1467,7 +1487,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse 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; } @@ -1488,7 +1508,7 @@ public function upsertRequest($batch_input_simple_public_object_batch_input_upse } 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/Tickets/Api/SearchApi.php b/codegen/Crm/Tickets/Api/SearchApi.php index 7a7e166b8..9d81c39b3 100644 --- a/codegen/Crm/Tickets/Api/SearchApi.php +++ b/codegen/Crm/Tickets/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\Tickets\ApiException; @@ -164,13 +164,16 @@ public function doSearchWithHttpInfo($public_object_search_request, string $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(), @@ -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 doSearchRequest($public_object_search_request, string $contentTy 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; } @@ -377,7 +381,7 @@ public function doSearchRequest($public_object_search_request, string $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/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/Events/Send/Api/BasicApi.php b/codegen/Events/Send/Api/BasicApi.php index 6f2c116f7..43ff1af19 100644 --- a/codegen/Events/Send/Api/BasicApi.php +++ b/codegen/Events/Send/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\Events\Send\ApiException; @@ -163,13 +163,16 @@ public function sendWithHttpInfo($behavioral_event_http_completion_request, 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(), @@ -243,8 +246,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)', @@ -252,8 +256,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -300,7 +304,7 @@ public function sendRequest($behavioral_event_http_completion_request, string $c if (isset($behavioral_event_http_completion_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($behavioral_event_http_completion_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($behavioral_event_http_completion_request), JSON_THROW_ON_ERROR); } else { $httpBody = $behavioral_event_http_completion_request; } @@ -321,7 +325,7 @@ public function sendRequest($behavioral_event_http_completion_request, 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/Events/Send/Api/BatchApi.php b/codegen/Events/Send/Api/BatchApi.php index 5b1f7ec33..816116166 100644 --- a/codegen/Events/Send/Api/BatchApi.php +++ b/codegen/Events/Send/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\Events\Send\ApiException; @@ -163,13 +163,16 @@ public function sendWithHttpInfo($batched_behavioral_event_http_completion_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(), @@ -243,8 +246,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)', @@ -252,8 +256,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -300,7 +304,7 @@ public function sendRequest($batched_behavioral_event_http_completion_request, s if (isset($batched_behavioral_event_http_completion_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($batched_behavioral_event_http_completion_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batched_behavioral_event_http_completion_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batched_behavioral_event_http_completion_request; } @@ -321,7 +325,7 @@ public function sendRequest($batched_behavioral_event_http_completion_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/Files/Api/FilesApi.php b/codegen/Files/Api/FilesApi.php index a15e8bfd0..ca75df9fc 100644 --- a/codegen/Files/Api/FilesApi.php +++ b/codegen/Files/Api/FilesApi.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\Files\ApiException; @@ -193,13 +193,16 @@ public function archiveWithHttpInfo($file_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(), @@ -273,8 +276,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)', @@ -282,8 +286,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -355,7 +359,7 @@ public function archiveRequest($file_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); @@ -427,13 +431,16 @@ public function checkImportWithHttpInfo($task_id, 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(), @@ -562,8 +569,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)', @@ -571,8 +579,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -641,7 +649,7 @@ public function checkImportRequest($task_id, 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); @@ -712,13 +720,16 @@ public function deleteWithHttpInfo($file_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(), @@ -792,8 +803,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)', @@ -801,8 +813,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -874,7 +886,7 @@ public function deleteRequest($file_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); @@ -1016,13 +1028,16 @@ public function doSearchWithHttpInfo($properties = null, $after = null, $before 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(), @@ -1221,8 +1236,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)', @@ -1230,8 +1246,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1680,7 +1696,7 @@ public function doSearchRequest($properties = null, $after = null, $before = nul } 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); @@ -1754,13 +1770,16 @@ public function getByIdWithHttpInfo($file_id, $properties = 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(), @@ -1891,8 +1910,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)', @@ -1900,8 +1920,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1984,7 +2004,7 @@ public function getByIdRequest($file_id, $properties = 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); @@ -2058,13 +2078,16 @@ public function getMetadataWithHttpInfo($path, $properties = null, 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(), @@ -2195,8 +2218,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)', @@ -2204,8 +2228,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2288,7 +2312,7 @@ public function getMetadataRequest($path, $properties = null, 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); @@ -2366,13 +2390,16 @@ public function getSignedUrlWithHttpInfo($file_id, $size = null, $expiration_sec 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(), @@ -2507,8 +2534,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)', @@ -2516,8 +2544,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2622,7 +2650,7 @@ public function getSignedUrlRequest($file_id, $size = null, $expiration_seconds } 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); @@ -2694,13 +2722,16 @@ public function importFromUrlWithHttpInfo($import_from_url_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(), @@ -2829,8 +2860,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)', @@ -2838,8 +2870,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2886,7 +2918,7 @@ public function importFromUrlRequest($import_from_url_input, string $contentType if (isset($import_from_url_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($import_from_url_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($import_from_url_input), JSON_THROW_ON_ERROR); } else { $httpBody = $import_from_url_input; } @@ -2907,7 +2939,7 @@ public function importFromUrlRequest($import_from_url_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); @@ -2985,13 +3017,16 @@ public function replaceWithHttpInfo($file_id, $charset_hunch = null, $file = nul 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(), @@ -3126,8 +3161,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)', @@ -3135,8 +3171,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3226,7 +3262,7 @@ public function replaceRequest($file_id, $charset_hunch = null, $file = null, $o } 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); @@ -3300,13 +3336,16 @@ public function updatePropertiesWithHttpInfo($file_id, $file_update_input, 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(), @@ -3437,8 +3476,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 +3486,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3513,7 +3553,7 @@ public function updatePropertiesRequest($file_id, $file_update_input, string $co if (isset($file_update_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($file_update_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($file_update_input), JSON_THROW_ON_ERROR); } else { $httpBody = $file_update_input; } @@ -3534,7 +3574,7 @@ public function updatePropertiesRequest($file_id, $file_update_input, 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); @@ -3616,13 +3656,16 @@ public function uploadWithHttpInfo($charset_hunch = null, $file = null, $file_na 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(), @@ -3761,8 +3804,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)', @@ -3770,8 +3814,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3851,7 +3895,7 @@ public function uploadRequest($charset_hunch = null, $file = null, $file_name = } 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/Files/Api/FoldersApi.php b/codegen/Files/Api/FoldersApi.php index e3d3454a0..bd50ee2b9 100644 --- a/codegen/Files/Api/FoldersApi.php +++ b/codegen/Files/Api/FoldersApi.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\Files\ApiException; @@ -187,13 +187,16 @@ public function archiveWithHttpInfo($folder_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(), @@ -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 ); } ); @@ -349,7 +353,7 @@ public function archiveRequest($folder_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); @@ -420,13 +424,16 @@ public function archiveByPathWithHttpInfo($folder_path, 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(), @@ -500,8 +507,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)', @@ -509,8 +517,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -582,7 +590,7 @@ public function archiveByPathRequest($folder_path, 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); @@ -654,13 +662,16 @@ public function checkUpdateStatusWithHttpInfo($task_id, 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(), @@ -789,8 +800,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)', @@ -798,8 +810,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -868,7 +880,7 @@ public function checkUpdateStatusRequest($task_id, 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); @@ -940,13 +952,16 @@ public function createWithHttpInfo($folder_input, 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(), @@ -1075,8 +1090,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)', @@ -1084,8 +1100,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1132,7 +1148,7 @@ public function createRequest($folder_input, string $contentType = self::content if (isset($folder_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($folder_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($folder_input), JSON_THROW_ON_ERROR); } else { $httpBody = $folder_input; } @@ -1153,7 +1169,7 @@ public function createRequest($folder_input, 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); @@ -1257,13 +1273,16 @@ public function doSearchWithHttpInfo($properties = null, $after = null, $before 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(), @@ -1424,8 +1443,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)', @@ -1433,8 +1453,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1674,7 +1694,7 @@ public function doSearchRequest($properties = null, $after = null, $before = nul } 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); @@ -1748,13 +1768,16 @@ public function getByIdWithHttpInfo($folder_id, $properties = null, string $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(), @@ -1885,8 +1908,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)', @@ -1894,8 +1918,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1978,7 +2002,7 @@ public function getByIdRequest($folder_id, $properties = null, string $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); @@ -2052,13 +2076,16 @@ public function getByPathWithHttpInfo($folder_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(), @@ -2189,8 +2216,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)', @@ -2198,8 +2226,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2282,7 +2310,7 @@ public function getByPathRequest($folder_path, $properties = 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); @@ -2356,13 +2384,16 @@ public function updatePropertiesWithHttpInfo($folder_id, $folder_update_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(), @@ -2493,8 +2524,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)', @@ -2502,8 +2534,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2569,7 +2601,7 @@ public function updatePropertiesRequest($folder_id, $folder_update_input, string if (isset($folder_update_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($folder_update_input)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($folder_update_input), JSON_THROW_ON_ERROR); } else { $httpBody = $folder_update_input; } @@ -2590,7 +2622,7 @@ public function updatePropertiesRequest($folder_id, $folder_update_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); @@ -2662,13 +2694,16 @@ public function updatePropertiesRecursivelyWithHttpInfo($folder_update_input_wit 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(), @@ -2797,8 +2832,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)', @@ -2806,8 +2842,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2854,7 +2890,7 @@ public function updatePropertiesRecursivelyRequest($folder_update_input_with_id, if (isset($folder_update_input_with_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($folder_update_input_with_id)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($folder_update_input_with_id), JSON_THROW_ON_ERROR); } else { $httpBody = $folder_update_input_with_id; } @@ -2875,7 +2911,7 @@ public function updatePropertiesRecursivelyRequest($folder_update_input_with_id, } 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/EmailsApi.php b/codegen/Marketing/Emails/Api/EmailsApi.php index 7ec799ee5..06aad9997 100644 --- a/codegen/Marketing/Emails/Api/EmailsApi.php +++ b/codegen/Marketing/Emails/Api/EmailsApi.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; @@ -213,13 +213,16 @@ public function archiveWithHttpInfo($email_id, $archived = 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(), @@ -295,8 +298,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)', @@ -304,8 +308,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 archiveRequest($email_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); @@ -457,13 +461,16 @@ public function callCloneWithHttpInfo($email_clone_request_v_next, 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(), @@ -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 ); } ); @@ -649,7 +657,7 @@ public function callCloneRequest($email_clone_request_v_next, string $contentTyp if (isset($email_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($email_clone_request_v_next)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($email_clone_request_v_next), JSON_THROW_ON_ERROR); } else { $httpBody = $email_clone_request_v_next; } @@ -670,7 +678,7 @@ public function callCloneRequest($email_clone_request_v_next, 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); @@ -742,13 +750,16 @@ public function createWithHttpInfo($email_create_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 createRequest($email_create_request, string $contentType = self: if (isset($email_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($email_create_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($email_create_request), JSON_THROW_ON_ERROR); } else { $httpBody = $email_create_request; } @@ -955,7 +967,7 @@ public function createRequest($email_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); @@ -1027,13 +1039,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(), @@ -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 ); } ); @@ -1219,7 +1235,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; } @@ -1240,7 +1256,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); @@ -1324,13 +1340,16 @@ public function getAbTestVariationWithHttpInfo($email_id, $archived = null, $inc 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(), @@ -1471,8 +1490,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)', @@ -1480,8 +1500,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1616,7 +1636,7 @@ public function getAbTestVariationRequest($email_id, $archived = null, $included } 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); @@ -1700,13 +1720,16 @@ public function getByIdWithHttpInfo($email_id, $include_stats = null, $marketing 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(), @@ -1847,8 +1870,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)', @@ -1856,8 +1880,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1992,7 +2016,7 @@ public function getByIdRequest($email_id, $include_stats = null, $marketing_camp } 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); @@ -2064,13 +2088,16 @@ public function getDraftWithHttpInfo($email_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(), @@ -2199,8 +2226,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)', @@ -2208,8 +2236,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2278,7 +2306,7 @@ public function getDraftRequest($email_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); @@ -2390,13 +2418,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(), @@ -2565,8 +2596,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)', @@ -2574,8 +2606,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2859,7 +2891,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); @@ -2933,13 +2965,16 @@ public function getRevisionByIdWithHttpInfo($email_id, $revision_id, 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(), @@ -3070,8 +3105,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)', @@ -3079,8 +3115,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3165,7 +3201,7 @@ public function getRevisionByIdRequest($email_id, $revision_id, 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); @@ -3243,13 +3279,16 @@ public function getRevisionsWithHttpInfo($email_id, $after = null, $before = nul 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(), @@ -3384,8 +3423,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)', @@ -3393,8 +3433,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3496,7 +3536,7 @@ public function getRevisionsRequest($email_id, $after = null, $before = null, $l } 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); @@ -3567,13 +3607,16 @@ public function publishOrSendWithHttpInfo($email_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(), @@ -3647,8 +3690,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)', @@ -3656,8 +3700,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3726,7 +3770,7 @@ public function publishOrSendRequest($email_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); @@ -3797,13 +3841,16 @@ public function resetDraftWithHttpInfo($email_id, 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(), @@ -3877,8 +3924,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)', @@ -3886,8 +3934,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -3956,7 +4004,7 @@ public function resetDraftRequest($email_id, 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); @@ -4030,13 +4078,16 @@ public function restoreDraftRevisionWithHttpInfo($email_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(), @@ -4167,8 +4218,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)', @@ -4176,8 +4228,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4262,7 +4314,7 @@ public function restoreDraftRevisionRequest($email_id, $revision_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); @@ -4335,13 +4387,16 @@ public function restoreRevisionWithHttpInfo($email_id, $revision_id, 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(), @@ -4417,8 +4472,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)', @@ -4426,8 +4482,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4512,7 +4568,7 @@ public function restoreRevisionRequest($email_id, $revision_id, 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); @@ -4583,13 +4639,16 @@ public function unpublishOrCancelWithHttpInfo($email_id, 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(), @@ -4663,8 +4722,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)', @@ -4672,8 +4732,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -4742,7 +4802,7 @@ public function unpublishOrCancelRequest($email_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); @@ -4818,13 +4878,16 @@ public function updateWithHttpInfo($email_id, $email_update_request, $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(), @@ -4957,8 +5020,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)', @@ -4966,8 +5030,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5041,7 +5105,7 @@ public function updateRequest($email_id, $email_update_request, $archived = null if (isset($email_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($email_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($email_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $email_update_request; } @@ -5062,7 +5126,7 @@ public function updateRequest($email_id, $email_update_request, $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); @@ -5136,13 +5200,16 @@ public function upsertDraftWithHttpInfo($email_id, $email_update_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(), @@ -5273,8 +5340,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)', @@ -5282,8 +5350,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -5346,7 +5414,7 @@ public function upsertDraftRequest($email_id, $email_update_request, string $con if (isset($email_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($email_update_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($email_update_request), JSON_THROW_ON_ERROR); } else { $httpBody = $email_update_request; } @@ -5367,7 +5435,7 @@ public function upsertDraftRequest($email_id, $email_update_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); 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/Events/Api/BasicApi.php b/codegen/Marketing/Events/Api/BasicApi.php index 9c6fcf73f..26909243c 100644 --- a/codegen/Marketing/Events/Api/BasicApi.php +++ b/codegen/Marketing/Events/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\Marketing\Events\ApiException; @@ -189,13 +189,16 @@ public function archiveWithHttpInfo($external_event_id, $external_account_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(), @@ -271,8 +274,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)', @@ -280,8 +284,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -367,7 +371,7 @@ public function archiveRequest($external_event_id, $external_account_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); @@ -438,13 +442,16 @@ public function archiveByObjectIdWithHttpInfo($object_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(), @@ -518,8 +525,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)', @@ -527,8 +535,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -597,7 +605,7 @@ public function archiveByObjectIdRequest($object_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); @@ -669,13 +677,16 @@ public function createWithHttpInfo($marketing_event_create_request_params, 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(), @@ -804,8 +815,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)', @@ -813,8 +825,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -861,7 +873,7 @@ public function createRequest($marketing_event_create_request_params, string $co if (isset($marketing_event_create_request_params)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($marketing_event_create_request_params)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($marketing_event_create_request_params), JSON_THROW_ON_ERROR); } else { $httpBody = $marketing_event_create_request_params; } @@ -882,7 +894,7 @@ public function createRequest($marketing_event_create_request_params, 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); @@ -956,13 +968,16 @@ public function getAllWithHttpInfo($after = null, $limit = 10, 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(), @@ -1093,8 +1108,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)', @@ -1102,8 +1118,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1178,7 +1194,7 @@ public function getAllRequest($after = null, $limit = 10, 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); @@ -1250,13 +1266,16 @@ public function getByObjectIdWithHttpInfo($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(), @@ -1385,8 +1404,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)', @@ -1394,8 +1414,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1464,7 +1484,7 @@ public function getByObjectIdRequest($object_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); @@ -1538,13 +1558,16 @@ public function getDetailsWithHttpInfo($external_event_id, $external_account_id, 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(), @@ -1675,8 +1698,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)', @@ -1684,8 +1708,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1771,7 +1795,7 @@ public function getDetailsRequest($external_event_id, $external_account_id, 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); @@ -1847,13 +1871,16 @@ public function updateWithHttpInfo($external_event_id, $external_account_id, $ma 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(), @@ -1986,8 +2013,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)', @@ -1995,8 +2023,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2076,7 +2104,7 @@ public function updateRequest($external_event_id, $external_account_id, $marketi if (isset($marketing_event_update_request_params)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($marketing_event_update_request_params)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($marketing_event_update_request_params), JSON_THROW_ON_ERROR); } else { $httpBody = $marketing_event_update_request_params; } @@ -2097,7 +2125,7 @@ public function updateRequest($external_event_id, $external_account_id, $marketi } 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); @@ -2171,13 +2199,16 @@ public function updateByObjectIdWithHttpInfo($object_id, $marketing_event_public 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(), @@ -2308,8 +2339,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)', @@ -2317,8 +2349,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2381,7 +2413,7 @@ public function updateByObjectIdRequest($object_id, $marketing_event_public_upda if (isset($marketing_event_public_update_request_v2)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($marketing_event_public_update_request_v2)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($marketing_event_public_update_request_v2), JSON_THROW_ON_ERROR); } else { $httpBody = $marketing_event_public_update_request_v2; } @@ -2402,7 +2434,7 @@ public function updateByObjectIdRequest($object_id, $marketing_event_public_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); @@ -2476,13 +2508,16 @@ public function upsertWithHttpInfo($external_event_id, $marketing_event_create_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(), @@ -2613,8 +2648,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)', @@ -2622,8 +2658,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -2686,7 +2722,7 @@ public function upsertRequest($external_event_id, $marketing_event_create_reques if (isset($marketing_event_create_request_params)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($marketing_event_create_request_params)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($marketing_event_create_request_params), JSON_THROW_ON_ERROR); } else { $httpBody = $marketing_event_create_request_params; } @@ -2707,7 +2743,7 @@ public function upsertRequest($external_event_id, $marketing_event_create_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/Marketing/Events/Api/BatchApi.php b/codegen/Marketing/Events/Api/BatchApi.php index 10f140c8c..05dab0ee3 100644 --- a/codegen/Marketing/Events/Api/BatchApi.php +++ b/codegen/Marketing/Events/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\Marketing\Events\ApiException; @@ -173,13 +173,16 @@ public function archiveWithHttpInfo($batch_input_marketing_event_external_unique 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(), @@ -294,8 +297,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)', @@ -303,8 +307,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -351,7 +355,7 @@ public function archiveRequest($batch_input_marketing_event_external_unique_iden if (isset($batch_input_marketing_event_external_unique_identifier)) { 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_marketing_event_external_unique_identifier)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_external_unique_identifier), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_external_unique_identifier; } @@ -372,7 +376,7 @@ public function archiveRequest($batch_input_marketing_event_external_unique_iden } 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); @@ -443,13 +447,16 @@ public function archiveByObjectIdWithHttpInfo($batch_input_marketing_event_publi 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(), @@ -523,8 +530,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)', @@ -532,8 +540,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -580,7 +588,7 @@ public function archiveByObjectIdRequest($batch_input_marketing_event_public_obj if (isset($batch_input_marketing_event_public_object_id_delete_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_marketing_event_public_object_id_delete_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_public_object_id_delete_request), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_public_object_id_delete_request; } @@ -601,7 +609,7 @@ public function archiveByObjectIdRequest($batch_input_marketing_event_public_obj } 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); @@ -673,13 +681,16 @@ public function updateByObjectIdWithHttpInfo($batch_input_marketing_event_public 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(), @@ -822,8 +833,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)', @@ -831,8 +843,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -879,7 +891,7 @@ public function updateByObjectIdRequest($batch_input_marketing_event_public_upda if (isset($batch_input_marketing_event_public_update_request_full_v2)) { 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_marketing_event_public_update_request_full_v2)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_public_update_request_full_v2), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_public_update_request_full_v2; } @@ -900,7 +912,7 @@ public function updateByObjectIdRequest($batch_input_marketing_event_public_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); @@ -972,13 +984,16 @@ public function upsertWithHttpInfo($batch_input_marketing_event_create_request_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(), @@ -1107,8 +1122,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)', @@ -1116,8 +1132,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1164,7 +1180,7 @@ public function upsertRequest($batch_input_marketing_event_create_request_params if (isset($batch_input_marketing_event_create_request_params)) { 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_marketing_event_create_request_params)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_create_request_params), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_create_request_params; } @@ -1185,7 +1201,7 @@ public function upsertRequest($batch_input_marketing_event_create_request_params } 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/Events/Api/EventAttendeesApi.php b/codegen/Marketing/Events/Api/EventAttendeesApi.php index b4fcb815e..ebe6bd935 100644 --- a/codegen/Marketing/Events/Api/EventAttendeesApi.php +++ b/codegen/Marketing/Events/Api/EventAttendeesApi.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\Events\ApiException; @@ -179,13 +179,16 @@ public function recordByContactEmailsWithHttpInfo($external_event_id, $subscribe 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(), @@ -320,8 +323,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)', @@ -329,8 +333,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -420,7 +424,7 @@ public function recordByContactEmailsRequest($external_event_id, $subscriber_sta if (isset($batch_input_marketing_event_email_subscriber)) { 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_marketing_event_email_subscriber)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_email_subscriber), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_email_subscriber; } @@ -441,7 +445,7 @@ public function recordByContactEmailsRequest($external_event_id, $subscriber_sta } 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); @@ -517,13 +521,16 @@ public function recordByContactIdWithHttpInfo($object_id, $subscriber_state, $ba 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(), @@ -656,8 +663,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)', @@ -665,8 +673,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -745,7 +753,7 @@ public function recordByContactIdRequest($object_id, $subscriber_state, $batch_i if (isset($batch_input_marketing_event_subscriber)) { 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_marketing_event_subscriber)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_subscriber), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_subscriber; } @@ -766,7 +774,7 @@ public function recordByContactIdRequest($object_id, $subscriber_state, $batch_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); @@ -844,13 +852,16 @@ public function recordByContactIdsWithHttpInfo($external_event_id, $subscriber_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(), @@ -985,8 +996,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)', @@ -994,8 +1006,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1085,7 +1097,7 @@ public function recordByContactIdsRequest($external_event_id, $subscriber_state, if (isset($batch_input_marketing_event_subscriber)) { 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_marketing_event_subscriber)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_subscriber), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_subscriber; } @@ -1106,7 +1118,7 @@ public function recordByContactIdsRequest($external_event_id, $subscriber_state, } 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); @@ -1182,13 +1194,16 @@ public function recordByEmailWithHttpInfo($object_id, $subscriber_state, $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(), @@ -1321,8 +1336,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)', @@ -1330,8 +1346,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1410,7 +1426,7 @@ public function recordByEmailRequest($object_id, $subscriber_state, $batch_input if (isset($batch_input_marketing_event_email_subscriber)) { 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_marketing_event_email_subscriber)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_email_subscriber), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_email_subscriber; } @@ -1431,7 +1447,7 @@ public function recordByEmailRequest($object_id, $subscriber_state, $batch_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/Marketing/Events/Api/EventStatusApi.php b/codegen/Marketing/Events/Api/EventStatusApi.php index 96e6ba644..3c3fa1a81 100644 --- a/codegen/Marketing/Events/Api/EventStatusApi.php +++ b/codegen/Marketing/Events/Api/EventStatusApi.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\Events\ApiException; @@ -169,13 +169,16 @@ public function cancelWithHttpInfo($external_event_id, $external_account_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(), @@ -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 ); } ); @@ -402,7 +406,7 @@ public function cancelRequest($external_event_id, $external_account_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); @@ -478,13 +482,16 @@ public function completeWithHttpInfo($external_event_id, $external_account_id, $ 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(), @@ -617,8 +624,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)', @@ -626,8 +634,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -707,7 +715,7 @@ public function completeRequest($external_event_id, $external_account_id, $marke if (isset($marketing_event_complete_request_params)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($marketing_event_complete_request_params)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($marketing_event_complete_request_params), JSON_THROW_ON_ERROR); } else { $httpBody = $marketing_event_complete_request_params; } @@ -728,7 +736,7 @@ public function completeRequest($external_event_id, $external_account_id, $marke } 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/Events/Api/IdentifiersApi.php b/codegen/Marketing/Events/Api/IdentifiersApi.php index fecb6d166..320dc388f 100644 --- a/codegen/Marketing/Events/Api/IdentifiersApi.php +++ b/codegen/Marketing/Events/Api/IdentifiersApi.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\Events\ApiException; @@ -167,13 +167,16 @@ public function doSearchWithHttpInfo($q, 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(), @@ -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 ); } ); @@ -382,7 +386,7 @@ public function doSearchRequest($q, string $contentType = self::contentTypes['do } 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); @@ -454,13 +458,16 @@ public function searchPortalEventsWithHttpInfo($external_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(), @@ -589,8 +596,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)', @@ -598,8 +606,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -668,7 +676,7 @@ public function searchPortalEventsRequest($external_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); diff --git a/codegen/Marketing/Events/Api/ListAssociationsApi.php b/codegen/Marketing/Events/Api/ListAssociationsApi.php index fc0ccee42..65e823928 100644 --- a/codegen/Marketing/Events/Api/ListAssociationsApi.php +++ b/codegen/Marketing/Events/Api/ListAssociationsApi.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\Events\ApiException; @@ -182,13 +182,16 @@ public function associateByExternalAccountAndEventIdsWithHttpInfo($external_acco 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 associateByExternalAccountAndEventIdsRequest($external_account_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); @@ -450,13 +454,16 @@ public function associateByMarketingEventIdWithHttpInfo($list_id, $marketing_eve 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(), @@ -532,8 +539,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)', @@ -541,8 +549,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -627,7 +635,7 @@ public function associateByMarketingEventIdRequest($list_id, $marketing_event_id } 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); @@ -702,13 +710,16 @@ public function disassociateByExternalAccountAndEventIdsWithHttpInfo($external_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(), @@ -786,8 +797,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)', @@ -795,8 +807,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -897,7 +909,7 @@ public function disassociateByExternalAccountAndEventIdsRequest($external_accoun } 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); @@ -970,13 +982,16 @@ public function disassociateByMarketingEventIdWithHttpInfo($list_id, $marketing_ 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(), @@ -1052,8 +1067,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)', @@ -1061,8 +1077,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1147,7 +1163,7 @@ public function disassociateByMarketingEventIdRequest($list_id, $marketing_event } 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); @@ -1221,13 +1237,16 @@ public function getAllByExternalAccountAndEventIdsWithHttpInfo($external_account 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(), @@ -1358,8 +1377,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)', @@ -1367,8 +1387,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1453,7 +1473,7 @@ public function getAllByExternalAccountAndEventIdsRequest($external_account_id, } 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); @@ -1525,13 +1545,16 @@ public function getAllByMarketingEventIdWithHttpInfo($marketing_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(), @@ -1660,8 +1683,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)', @@ -1669,8 +1693,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1739,7 +1763,7 @@ public function getAllByMarketingEventIdRequest($marketing_event_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); diff --git a/codegen/Marketing/Events/Api/ParticipantStateApi.php b/codegen/Marketing/Events/Api/ParticipantStateApi.php index c515af041..bdb23ec75 100644 --- a/codegen/Marketing/Events/Api/ParticipantStateApi.php +++ b/codegen/Marketing/Events/Api/ParticipantStateApi.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\Events\ApiException; @@ -182,13 +182,16 @@ public function getParticipationsBreakdownByContactIdWithHttpInfo($contact_ident 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 ); } ); @@ -435,7 +439,7 @@ public function getParticipationsBreakdownByContactIdRequest($contact_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); @@ -517,13 +521,16 @@ public function getParticipationsBreakdownByExternalEventIdWithHttpInfo($externa 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(), @@ -662,8 +669,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)', @@ -671,8 +679,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -801,7 +809,7 @@ public function getParticipationsBreakdownByExternalEventIdRequest($external_acc } 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); @@ -881,13 +889,16 @@ public function getParticipationsBreakdownByMarketingEventIdWithHttpInfo($market 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(), @@ -1024,8 +1035,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)', @@ -1033,8 +1045,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1147,7 +1159,7 @@ public function getParticipationsBreakdownByMarketingEventIdRequest($marketing_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); @@ -1221,13 +1233,16 @@ public function getParticipationsCountersByEventExternalIdWithHttpInfo($external 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(), @@ -1358,8 +1373,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)', @@ -1367,8 +1383,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1453,7 +1469,7 @@ public function getParticipationsCountersByEventExternalIdRequest($external_acco } 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); @@ -1525,13 +1541,16 @@ public function getParticipationsCountersByMarketingEventIdWithHttpInfo($marketi 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(), @@ -1660,8 +1679,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)', @@ -1669,8 +1689,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1739,7 +1759,7 @@ public function getParticipationsCountersByMarketingEventIdRequest($marketing_ev } 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/Events/Api/SettingsApi.php b/codegen/Marketing/Events/Api/SettingsApi.php index 9ce182aa7..e52a17ac1 100644 --- a/codegen/Marketing/Events/Api/SettingsApi.php +++ b/codegen/Marketing/Events/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\Marketing\Events\ApiException; @@ -167,13 +167,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(), @@ -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 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); @@ -456,13 +460,16 @@ public function updateWithHttpInfo($app_id, $event_detail_settings_url, 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(), @@ -593,8 +600,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)', @@ -602,8 +610,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 updateRequest($app_id, $event_detail_settings_url, string $conte if (isset($event_detail_settings_url)) { if (stripos($headers['Content-Type'], 'application/json') !== false) { # if Content-Type contains "application/json", json_encode the body - $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($event_detail_settings_url)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($event_detail_settings_url), JSON_THROW_ON_ERROR); } else { $httpBody = $event_detail_settings_url; } @@ -687,7 +695,7 @@ public function updateRequest($app_id, $event_detail_settings_url, 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); diff --git a/codegen/Marketing/Events/Api/SubscriberStateChangesApi.php b/codegen/Marketing/Events/Api/SubscriberStateChangesApi.php index 8de157126..fb9d9ff80 100644 --- a/codegen/Marketing/Events/Api/SubscriberStateChangesApi.php +++ b/codegen/Marketing/Events/Api/SubscriberStateChangesApi.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\Events\ApiException; @@ -173,13 +173,16 @@ public function upsertByContactEmailWithHttpInfo($external_event_id, $subscriber 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(), @@ -300,8 +303,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)', @@ -309,8 +313,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 upsertByContactEmailRequest($external_event_id, $subscriber_stat if (isset($batch_input_marketing_event_email_subscriber)) { 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_marketing_event_email_subscriber)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_email_subscriber), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_email_subscriber; } @@ -427,7 +431,7 @@ public function upsertByContactEmailRequest($external_event_id, $subscriber_stat } 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 upsertByContactIdWithHttpInfo($external_event_id, $subscriber_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(), @@ -632,8 +639,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)', @@ -641,8 +649,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -738,7 +746,7 @@ public function upsertByContactIdRequest($external_event_id, $subscriber_state, if (isset($batch_input_marketing_event_subscriber)) { 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_marketing_event_subscriber)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($batch_input_marketing_event_subscriber), JSON_THROW_ON_ERROR); } else { $httpBody = $batch_input_marketing_event_subscriber; } @@ -759,7 +767,7 @@ public function upsertByContactIdRequest($external_event_id, $subscriber_state, } 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/Marketing/Transactional/Api/SMTPTokensApi.php b/codegen/Marketing/Transactional/Api/SMTPTokensApi.php index c945a24d7..38ac42f6c 100644 --- a/codegen/Marketing/Transactional/Api/SMTPTokensApi.php +++ b/codegen/Marketing/Transactional/Api/SMTPTokensApi.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\Transactional\ApiException; @@ -175,13 +175,16 @@ public function archiveTokenWithHttpInfo($token_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 archiveTokenRequest($token_id, 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); @@ -406,13 +410,16 @@ public function createTokenWithHttpInfo($smtp_api_token_request_egg, 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 createTokenRequest($smtp_api_token_request_egg, string $contentT if (isset($smtp_api_token_request_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($smtp_api_token_request_egg)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($smtp_api_token_request_egg), JSON_THROW_ON_ERROR); } else { $httpBody = $smtp_api_token_request_egg; } @@ -619,7 +627,7 @@ public function createTokenRequest($smtp_api_token_request_egg, 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 getTokenByIdWithHttpInfo($token_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 getTokenByIdRequest($token_id, 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); @@ -983,13 +995,16 @@ public function getTokensPageWithHttpInfo($campaign_name = null, $email_campaign 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 ); } ); @@ -1231,7 +1247,7 @@ public function getTokensPageRequest($campaign_name = null, $email_campaign_id = } 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); @@ -1303,13 +1319,16 @@ public function resetPasswordWithHttpInfo($token_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(), @@ -1438,8 +1457,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)', @@ -1447,8 +1467,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1517,7 +1537,7 @@ public function resetPasswordRequest($token_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/Marketing/Transactional/Api/SendTransactionalEmailApi.php b/codegen/Marketing/Transactional/Api/SendTransactionalEmailApi.php index 30680e3c3..d07b82d65 100644 --- a/codegen/Marketing/Transactional/Api/SendTransactionalEmailApi.php +++ b/codegen/Marketing/Transactional/Api/SendTransactionalEmailApi.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\Transactional\ApiException; @@ -164,13 +164,16 @@ public function sendEmailWithHttpInfo($public_single_send_request_egg, 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(), @@ -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 sendEmailRequest($public_single_send_request_egg, string $conten if (isset($public_single_send_request_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($public_single_send_request_egg)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_single_send_request_egg), JSON_THROW_ON_ERROR); } else { $httpBody = $public_single_send_request_egg; } @@ -377,7 +381,7 @@ public function sendEmailRequest($public_single_send_request_egg, 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/Oauth/Api/AccessTokensApi.php b/codegen/Oauth/Api/AccessTokensApi.php index 5e6df6246..202574401 100644 --- a/codegen/Oauth/Api/AccessTokensApi.php +++ b/codegen/Oauth/Api/AccessTokensApi.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\Oauth\ApiException; @@ -166,13 +166,16 @@ public function getWithHttpInfo($token, string $contentType = self::contentTypes 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 ); } ); @@ -383,7 +387,7 @@ public function getRequest($token, string $contentType = self::contentTypes['get } 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/Oauth/Api/RefreshTokensApi.php b/codegen/Oauth/Api/RefreshTokensApi.php index 4f49cbe6b..b13d0a26e 100644 --- a/codegen/Oauth/Api/RefreshTokensApi.php +++ b/codegen/Oauth/Api/RefreshTokensApi.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\Oauth\ApiException; @@ -168,13 +168,16 @@ public function archiveWithHttpInfo($token, 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(), @@ -250,8 +253,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)', @@ -259,8 +263,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -330,7 +334,7 @@ public function archiveRequest($token, 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); @@ -400,13 +404,16 @@ public function getWithHttpInfo($token, string $contentType = self::contentTypes 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(), @@ -537,8 +544,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)', @@ -546,8 +554,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -617,7 +625,7 @@ public function getRequest($token, string $contentType = self::contentTypes['get } 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/Oauth/Api/TokensApi.php b/codegen/Oauth/Api/TokensApi.php index f4b0b1e0c..9f815915b 100644 --- a/codegen/Oauth/Api/TokensApi.php +++ b/codegen/Oauth/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\Oauth\ApiException; @@ -178,13 +178,16 @@ public function createWithHttpInfo($grant_type = null, $code = null, $redirect_u 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 ); } ); @@ -422,7 +426,7 @@ public function createRequest($grant_type = null, $code = null, $redirect_uri = } 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/Settings/Users/Api/RolesApi.php b/codegen/Settings/Users/Api/RolesApi.php index 870220c8c..835e5b0c9 100644 --- a/codegen/Settings/Users/Api/RolesApi.php +++ b/codegen/Settings/Users/Api/RolesApi.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\Users\ApiException; @@ -162,13 +162,16 @@ public function getAllWithHttpInfo(string $contentType = self::contentTypes['get 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 getAllRequest(string $contentType = self::contentTypes['getAll'] } 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/Users/Api/TeamsApi.php b/codegen/Settings/Users/Api/TeamsApi.php index 88010903f..9f40525bb 100644 --- a/codegen/Settings/Users/Api/TeamsApi.php +++ b/codegen/Settings/Users/Api/TeamsApi.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\Users\ApiException; @@ -162,13 +162,16 @@ public function getAllWithHttpInfo(string $contentType = self::contentTypes['get 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 getAllRequest(string $contentType = self::contentTypes['getAll'] } 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/Users/Api/UsersApi.php b/codegen/Settings/Users/Api/UsersApi.php index 30b290a8d..1c55139d0 100644 --- a/codegen/Settings/Users/Api/UsersApi.php +++ b/codegen/Settings/Users/Api/UsersApi.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\Users\ApiException; @@ -177,13 +177,16 @@ public function archiveWithHttpInfo($user_id, $id_property = null, 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(), @@ -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 ); } ); @@ -349,7 +353,7 @@ public function archiveRequest($user_id, $id_property = null, 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); @@ -421,13 +425,16 @@ public function createWithHttpInfo($user_provision_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(), @@ -556,8 +563,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)', @@ -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 createRequest($user_provision_request, string $contentType = sel if (isset($user_provision_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($user_provision_request)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($user_provision_request), JSON_THROW_ON_ERROR); } else { $httpBody = $user_provision_request; } @@ -634,7 +642,7 @@ public function createRequest($user_provision_request, 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); @@ -708,13 +716,16 @@ public function getByIdWithHttpInfo($user_id, $id_property = null, 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 ); } ); @@ -935,7 +947,7 @@ public function getByIdRequest($user_id, $id_property = null, 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); @@ -1009,13 +1021,16 @@ public function getPageWithHttpInfo($limit = null, $after = 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(), @@ -1146,8 +1161,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)', @@ -1155,8 +1171,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1231,7 +1247,7 @@ public function getPageRequest($limit = null, $after = 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); @@ -1307,13 +1323,16 @@ public function updateWithHttpInfo($user_id, $public_user_update, $id_property = 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(), @@ -1446,8 +1465,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)', @@ -1455,8 +1475,8 @@ function ($exception) { $exception->getRequest()->getUri() ), $statusCode, - $response->getHeaders(), - (string) $response->getBody() + $response ? $response->getHeaders() : null, + $response ? (string) $response->getBody() : null ); } ); @@ -1530,7 +1550,7 @@ public function updateRequest($user_id, $public_user_update, $id_property = null if (isset($public_user_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($public_user_update)); + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($public_user_update), JSON_THROW_ON_ERROR); } else { $httpBody = $public_user_update; } @@ -1551,7 +1571,7 @@ public function updateRequest($user_id, $public_user_update, $id_property = 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/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..53047871e 100644 --- a/lib/RetryMiddlewareFactory.php +++ b/lib/RetryMiddlewareFactory.php @@ -2,10 +2,10 @@ namespace HubSpot; -use GuzzleHttp\Exception\ConnectException; 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 +92,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 +130,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,15 +151,18 @@ 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) { + // Guzzle 7 reports connection failures as ConnectException, Guzzle 8 + // splits them across ConnectException and NetworkException. Both + // implement PSR-18's NetworkExceptionInterface. + if (!$exception instanceof NetworkExceptionInterface) { return false; } @@ -167,13 +170,8 @@ public static function getRetryFunctionByConnectionErrors( return true; } - $handlerContext = $exception->getHandlerContext(); - $errno = $handlerContext['errno'] ?? null; - - if (is_numeric($errno) && in_array((int) $errno, $curlErrorCodes, true)) { - return true; - } - + // RequestException::getHandlerContext() was removed in Guzzle 8, so the + // cURL errno is read from the exception message in both major versions. if (1 === preg_match('/cURL error\s+(\d+):/i', $exception->getMessage(), $matches)) { return in_array((int) $matches[1], $curlErrorCodes, true); } diff --git a/tests/Unit/GeneratedApiClientTest.php b/tests/Unit/GeneratedApiClientTest.php new file mode 100644 index 000000000..6ca8cdd19 --- /dev/null +++ b/tests/Unit/GeneratedApiClientTest.php @@ -0,0 +1,150 @@ +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..de5f66968 100644 --- a/tests/Unit/RetryMiddlewareFactoryTest.php +++ b/tests/Unit/RetryMiddlewareFactoryTest.php @@ -3,6 +3,7 @@ namespace Hubspot\Tests\Unit; use GuzzleHttp\Exception\ConnectException; +use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; use HubSpot\RetryMiddlewareFactory; use PHPUnit\Framework\TestCase; @@ -15,22 +16,20 @@ class RetryMiddlewareFactoryTest extends TestCase { /** @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 +48,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 +91,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));