From 272ac86e103d6af557d8314361c8fd911df1b29f Mon Sep 17 00:00:00 2001 From: Bastian Konetzny <5451122+bkonetzny@users.noreply.github.com> Date: Tue, 7 Apr 2026 13:12:49 +0200 Subject: [PATCH 1/2] Aligned exception handling of *AsyncWithHttpInfo with handling from *WithHttpInfo --- .../src/main/resources/php/api.mustache | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/php/api.mustache b/modules/openapi-generator/src/main/resources/php/api.mustache index 7d25f0d82d4e..9defb5b7b92f 100644 --- a/modules/openapi-generator/src/main/resources/php/api.mustache +++ b/modules/openapi-generator/src/main/resources/php/api.mustache @@ -482,17 +482,20 @@ use {{invokerPackage}}\ObjectSerializer; {{/returnType}} }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); From 3ec86ab32d652b49919f6956f097e84c84f9175d Mon Sep 17 00:00:00 2001 From: Bastian Konetzny <5451122+bkonetzny@users.noreply.github.com> Date: Thu, 23 Apr 2026 18:28:02 +0200 Subject: [PATCH 2/2] Updated php samples --- .../lib/Api/AnotherFakeApi.php | 23 +- .../OpenAPIClient-php/lib/Api/DefaultApi.php | 23 +- .../php/OpenAPIClient-php/lib/Api/FakeApi.php | 644 ++++++++++-------- .../lib/Api/FakeClassnameTags123Api.php | 23 +- .../php/OpenAPIClient-php/lib/Api/PetApi.php | 253 ++++--- .../OpenAPIClient-php/lib/Api/StoreApi.php | 92 +-- .../php/OpenAPIClient-php/lib/Api/UserApi.php | 184 ++--- 7 files changed, 702 insertions(+), 540 deletions(-) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php index 1d30d6737d37..2d0701241c2e 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php @@ -285,17 +285,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php index ae57fe2439d9..2c4f6d6e4f1a 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php @@ -273,17 +273,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php index 41ae26b81611..90ff41ea3753 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeApi.php @@ -360,17 +360,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -620,17 +623,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -919,17 +925,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1129,17 +1138,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1405,17 +1417,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1658,17 +1673,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1911,17 +1929,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2164,17 +2185,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2417,17 +2441,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2715,17 +2742,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2982,17 +3012,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -3263,17 +3296,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -3547,17 +3583,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -3814,17 +3853,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -4047,17 +4089,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -4319,17 +4364,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -4528,17 +4576,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -4737,17 +4788,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -4950,17 +5004,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -5234,17 +5291,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -5503,17 +5563,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -5854,17 +5917,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -6168,17 +6234,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -6458,17 +6527,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -6675,17 +6747,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -6896,17 +6971,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -7140,17 +7218,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -7455,17 +7536,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php index 82f119c6aea6..8e2720eedd42 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/FakeClassnameTags123Api.php @@ -285,17 +285,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php index 0e75b91decb8..30026e3e7974 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/PetApi.php @@ -343,17 +343,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -643,17 +646,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -921,17 +927,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1198,17 +1207,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1472,17 +1484,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1771,17 +1786,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2075,17 +2093,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2369,17 +2390,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2664,17 +2688,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -2989,17 +3016,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -3310,17 +3340,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php index 61f4a8fb2043..6a84634b2509 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/StoreApi.php @@ -244,17 +244,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -508,17 +511,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -765,17 +771,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1039,17 +1048,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php index 9ca803b93f67..da8f2ee3e9a7 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/Api/UserApi.php @@ -256,17 +256,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -473,17 +476,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -690,17 +696,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -907,17 +916,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1175,17 +1187,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1447,17 +1462,20 @@ function ($response) use ($returnType) { ]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1679,17 +1697,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } ); @@ -1885,17 +1906,20 @@ function ($response) use ($returnType) { return [null, $response->getStatusCode(), $response->getHeaders()]; }, function ($exception) { - $response = $exception->getResponse(); - $statusCode = $response->getStatusCode(); + if ($exception instanceof RequestException) { + throw new ApiException( + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + $exception->getResponse() ? $exception->getResponse()->getHeaders() : null, + $exception->getResponse() ? (string) $exception->getResponse()->getBody() : null + ); + } + throw new ApiException( - sprintf( - '[%d] Error connecting to the API (%s)', - $statusCode, - $exception->getRequest()->getUri() - ), - $statusCode, - $response->getHeaders(), - (string) $response->getBody() + "[{$exception->getCode()}] {$exception->getMessage()}", + (int) $exception->getCode(), + null, + null ); } );