Skip to content

Commit 3ec86ab

Browse files
committed
Updated php samples
1 parent 272ac86 commit 3ec86ab

7 files changed

Lines changed: 702 additions & 540 deletions

File tree

samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,20 @@ function ($response) use ($returnType) {
285285
];
286286
},
287287
function ($exception) {
288-
$response = $exception->getResponse();
289-
$statusCode = $response->getStatusCode();
288+
if ($exception instanceof RequestException) {
289+
throw new ApiException(
290+
"[{$exception->getCode()}] {$exception->getMessage()}",
291+
(int) $exception->getCode(),
292+
$exception->getResponse() ? $exception->getResponse()->getHeaders() : null,
293+
$exception->getResponse() ? (string) $exception->getResponse()->getBody() : null
294+
);
295+
}
296+
290297
throw new ApiException(
291-
sprintf(
292-
'[%d] Error connecting to the API (%s)',
293-
$statusCode,
294-
$exception->getRequest()->getUri()
295-
),
296-
$statusCode,
297-
$response->getHeaders(),
298-
(string) $response->getBody()
298+
"[{$exception->getCode()}] {$exception->getMessage()}",
299+
(int) $exception->getCode(),
300+
null,
301+
null
299302
);
300303
}
301304
);

samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,17 +273,20 @@ function ($response) use ($returnType) {
273273
];
274274
},
275275
function ($exception) {
276-
$response = $exception->getResponse();
277-
$statusCode = $response->getStatusCode();
276+
if ($exception instanceof RequestException) {
277+
throw new ApiException(
278+
"[{$exception->getCode()}] {$exception->getMessage()}",
279+
(int) $exception->getCode(),
280+
$exception->getResponse() ? $exception->getResponse()->getHeaders() : null,
281+
$exception->getResponse() ? (string) $exception->getResponse()->getBody() : null
282+
);
283+
}
284+
278285
throw new ApiException(
279-
sprintf(
280-
'[%d] Error connecting to the API (%s)',
281-
$statusCode,
282-
$exception->getRequest()->getUri()
283-
),
284-
$statusCode,
285-
$response->getHeaders(),
286-
(string) $response->getBody()
286+
"[{$exception->getCode()}] {$exception->getMessage()}",
287+
(int) $exception->getCode(),
288+
null,
289+
null
287290
);
288291
}
289292
);

0 commit comments

Comments
 (0)