Skip to content

Commit d402f35

Browse files
authored
Merge pull request #3163 from DanGe42/master
Improve error message for connection failures
2 parents d621021 + b16eda1 commit d402f35

File tree

15 files changed

+115
-185
lines changed

15 files changed

+115
-185
lines changed

modules/swagger-codegen/src/main/resources/php/ApiClient.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,19 @@ class ApiClient
224224

225225
// Handle the response
226226
if ($response_info['http_code'] == 0) {
227-
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
227+
$curl_error_message = curl_error($curl);
228+
229+
// curl_exec can sometimes fail but still return a blank message from curl_error().
230+
if (!empty($curl_error_message)) {
231+
$error_message = "API call to $url failed: $curl_error_message";
232+
} else {
233+
$error_message = "API call to $url failed, but for an unknown reason. " .
234+
"This could happen if you are disconnected from the network.";
235+
}
236+
237+
$exception = new ApiException($error_message, 0, null, null);
238+
$exception->setResponseObject($response_info);
239+
throw $exception;
228240
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) {
229241
// return raw body if response is a file
230242
if ($responseType == '\SplFileObject' || $responseType == 'string') {

samples/client/petstore-security-test/php/SwaggerClient-php/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# SwaggerClient-php
2-
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
2+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
33

44
This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
55

6-
- API version: 1.0.0 *_/ &#39; \&quot; &#x3D;end
7-
- Build date: 2016-07-02T16:22:07.280+08:00
6+
- API version: 1.0.0 */ &#39; &quot; &#x3D;end
7+
- Build date: 2016-07-06T12:09:22.895-07:00
88
- Build package: class io.swagger.codegen.languages.PhpClientCodegen
99

1010
## Requirements
@@ -58,7 +58,7 @@ Please follow the [installation procedure](#installation--usage) and then run th
5858
require_once(__DIR__ . '/vendor/autoload.php');
5959

6060
$api_instance = new Swagger\Client\Api\FakeApi();
61-
$test_code_inject____end = "test_code_inject____end_example"; // string | To test code injection *_/ ' \" =end
61+
$test_code_inject____end = "test_code_inject____end_example"; // string | To test code injection */ ' \" =end
6262

6363
try {
6464
$api_instance->testCodeInjectEnd($test_code_inject____end);
@@ -71,11 +71,11 @@ try {
7171

7272
## Documentation for API Endpoints
7373

74-
All URIs are relative to *https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end/v2 *_/ &#39; \&quot; &#x3D;end*
74+
All URIs are relative to *https://petstore.swagger.io */ &#39; &quot; &#x3D;end/v2 */ &#39; &quot; &#x3D;end*
7575

7676
Class | Method | HTTP request | Description
7777
------------ | ------------- | ------------- | -------------
78-
*FakeApi* | [**testCodeInjectEnd**](docs/Api/FakeApi.md#testcodeinjectend) | **PUT** /fake | To test code injection *_/ &#39; \&quot; &#x3D;end
78+
*FakeApi* | [**testCodeInjectEnd**](docs/Api/FakeApi.md#testcodeinjectend) | **PUT** /fake | To test code injection */ &#39; \&quot; &#x3D;end
7979

8080

8181
## Documentation For Models
@@ -86,12 +86,6 @@ Class | Method | HTTP request | Description
8686
## Documentation For Authorization
8787

8888

89-
## api_key
90-
91-
- **Type**: API key
92-
- **API key parameter name**: api_key */ ' " =end
93-
- **Location**: HTTP header
94-
9589
## petstore_auth
9690

9791
- **Type**: OAuth
@@ -101,9 +95,15 @@ Class | Method | HTTP request | Description
10195
- **write:pets**: modify pets in your account */ ' " =end
10296
- **read:pets**: read your pets */ ' " =end
10397

98+
## api_key
99+
100+
- **Type**: API key
101+
- **API key parameter name**: api_key */ ' " =end
102+
- **Location**: HTTP header
103+
104104

105105
## Author
106106

107-
[email protected] *_/ &#39; \&quot; &#x3D;end
107+
[email protected] */ &#39; &quot; &#x3D;end
108108

109109

samples/client/petstore-security-test/php/SwaggerClient-php/autoload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

33
/**
4-
* Swagger Petstore *_/ ' \" =end
4+
* Swagger Petstore */ ' " =end
55
*
6-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
6+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
77
*
8-
* OpenAPI spec version: 1.0.0 *_/ ' \" =end
9-
* Contact: [email protected] *_/ ' \" =end
8+
* OpenAPI spec version: 1.0.0 */ ' " =end
9+
* Contact: [email protected] */ ' " =end
1010
* Generated by: https://github.com/swagger-api/swagger-codegen.git
1111
*
1212
* Licensed under the Apache License, Version 2.0 (the "License");

samples/client/petstore-security-test/php/SwaggerClient-php/docs/Api/FakeApi.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# Swagger\Client\FakeApi
22

3-
All URIs are relative to *https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end/v2 *_/ &#39; \&quot; &#x3D;end*
3+
All URIs are relative to *https://petstore.swagger.io */ &#39; &quot; &#x3D;end/v2 */ &#39; &quot; &#x3D;end*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7-
[**testCodeInjectEnd**](FakeApi.md#testCodeInjectEnd) | **PUT** /fake | To test code injection *_/ &#39; \&quot; &#x3D;end
7+
[**testCodeInjectEnd**](FakeApi.md#testCodeInjectEnd) | **PUT** /fake | To test code injection */ &#39; \&quot; &#x3D;end
88

99

1010
# **testCodeInjectEnd**
1111
> testCodeInjectEnd($test_code_inject____end)
1212
13-
To test code injection *_/ ' \" =end
13+
To test code injection */ ' \" =end
1414

1515
### Example
1616
```php
1717
<?php
1818
require_once(__DIR__ . '/vendor/autoload.php');
1919

2020
$api_instance = new Swagger\Client\Api\FakeApi();
21-
$test_code_inject____end = "test_code_inject____end_example"; // string | To test code injection *_/ ' \" =end
21+
$test_code_inject____end = "test_code_inject____end_example"; // string | To test code injection */ ' \" =end
2222

2323
try {
2424
$api_instance->testCodeInjectEnd($test_code_inject____end);
@@ -32,7 +32,7 @@ try {
3232

3333
Name | Type | Description | Notes
3434
------------- | ------------- | ------------- | -------------
35-
**test_code_inject____end** | **string**| To test code injection *_/ &#39; \&quot; &#x3D;end | [optional]
35+
**test_code_inject____end** | **string**| To test code injection */ &#39; \&quot; &#x3D;end | [optional]
3636

3737
### Return type
3838

@@ -44,8 +44,8 @@ No authorization required
4444

4545
### HTTP request headers
4646

47-
- **Content-Type**: application/json, */ " =end
48-
- **Accept**: application/json, */ " =end
47+
- **Content-Type**: application/json, */ ' " =end
48+
- **Accept**: application/json, */ ' " =end
4949

5050
[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md)
5151

samples/client/petstore-security-test/php/SwaggerClient-php/docs/Model/ModelReturn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Properties
44
Name | Type | Description | Notes
55
------------ | ------------- | ------------- | -------------
6-
**return** | **int** | property description *_/ &#39; \&quot; &#x3D;end | [optional]
6+
**return** | **int** | property description */ &#39; \&quot; &#x3D;end | [optional]
77

88
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
99

samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212

1313
/**
14-
* Swagger Petstore *_/ ' \" =end
14+
* Swagger Petstore */ ' " =end
1515
*
16-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
16+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
1717
*
18-
* OpenAPI spec version: 1.0.0 *_/ ' \" =end
19-
* Contact: [email protected] *_/ ' \" =end
18+
* OpenAPI spec version: 1.0.0 */ ' " =end
19+
* Contact: [email protected] */ ' " =end
2020
* Generated by: https://github.com/swagger-api/swagger-codegen.git
2121
*
2222
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -73,7 +73,7 @@ public function __construct(\Swagger\Client\ApiClient $apiClient = null)
7373
{
7474
if ($apiClient == null) {
7575
$apiClient = new ApiClient();
76-
$apiClient->getConfig()->setHost('https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end/v2 *_/ &#39; \&quot; &#x3D;end');
76+
$apiClient->getConfig()->setHost('https://petstore.swagger.io */ &#39; &quot; &#x3D;end/v2 */ &#39; &quot; &#x3D;end');
7777
}
7878

7979
$this->apiClient = $apiClient;
@@ -105,9 +105,9 @@ public function setApiClient(\Swagger\Client\ApiClient $apiClient)
105105
/**
106106
* Operation testCodeInjectEnd
107107
*
108-
* To test code injection *_/ ' \" =end
108+
* To test code injection */ ' \" =end
109109
*
110-
* @param string $test_code_inject____end To test code injection *_/ &#39; \&quot; &#x3D;end (optional)
110+
* @param string $test_code_inject____end To test code injection */ &#39; \&quot; &#x3D;end (optional)
111111
* @return void
112112
* @throws \Swagger\Client\ApiException on non-2xx response
113113
*/
@@ -120,9 +120,9 @@ public function testCodeInjectEnd($test_code_inject____end = null)
120120
/**
121121
* Operation testCodeInjectEndWithHttpInfo
122122
*
123-
* To test code injection *_/ ' \" =end
123+
* To test code injection */ ' \" =end
124124
*
125-
* @param string $test_code_inject____end To test code injection *_/ &#39; \&quot; &#x3D;end (optional)
125+
* @param string $test_code_inject____end To test code injection */ &#39; \&quot; &#x3D;end (optional)
126126
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
127127
* @throws \Swagger\Client\ApiException on non-2xx response
128128
*/
@@ -134,11 +134,11 @@ public function testCodeInjectEndWithHttpInfo($test_code_inject____end = null)
134134
$queryParams = array();
135135
$headerParams = array();
136136
$formParams = array();
137-
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', '*/ " =end'));
137+
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', '*/ ' " =end'));
138138
if (!is_null($_header_accept)) {
139139
$headerParams['Accept'] = $_header_accept;
140140
}
141-
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','*/ " =end'));
141+
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','*/ ' " =end'));
142142

143143
// default format to json
144144
$resourcePath = str_replace("{format}", "json", $resourcePath);

samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
*/
1313

1414
/**
15-
* Swagger Petstore *_/ ' \" =end
15+
* Swagger Petstore */ ' " =end
1616
*
17-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
17+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
1818
*
19-
* OpenAPI spec version: 1.0.0 *_/ ' \" =end
20-
* Contact: [email protected] *_/ ' \" =end
19+
* OpenAPI spec version: 1.0.0 */ ' " =end
20+
* Contact: [email protected] */ ' " =end
2121
* Generated by: https://github.com/swagger-api/swagger-codegen.git
2222
*
2323
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -245,7 +245,19 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
245245

246246
// Handle the response
247247
if ($response_info['http_code'] == 0) {
248-
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
248+
$curl_error_message = curl_error($curl);
249+
250+
// curl_exec can sometimes fail but still return a blank message from curl_error().
251+
if (!empty($curl_error_message)) {
252+
$error_message = "API call to $url failed: $curl_error_message";
253+
} else {
254+
$error_message = "API call to $url failed, but for an unknown reason. " .
255+
"This could happen if you are disconnected from the network.";
256+
}
257+
258+
$exception = new ApiException($error_message, 0, null, null);
259+
$exception->setResponseObject($response_info);
260+
throw $exception;
249261
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) {
250262
// return raw body if response is a file
251263
if ($responseType == '\SplFileObject' || $responseType == 'string') {

samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212

1313
/**
14-
* Swagger Petstore *_/ ' \" =end
14+
* Swagger Petstore */ ' " =end
1515
*
16-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
16+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
1717
*
18-
* OpenAPI spec version: 1.0.0 *_/ ' \" =end
19-
* Contact: [email protected] *_/ ' \" =end
18+
* OpenAPI spec version: 1.0.0 */ ' " =end
19+
* Contact: [email protected] */ ' " =end
2020
* Generated by: https://github.com/swagger-api/swagger-codegen.git
2121
*
2222
* Licensed under the Apache License, Version 2.0 (the "License");

samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
*/
1212

1313
/**
14-
* Swagger Petstore *_/ ' \" =end
14+
* Swagger Petstore */ ' " =end
1515
*
16-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
16+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
1717
*
18-
* OpenAPI spec version: 1.0.0 *_/ ' \" =end
19-
* Contact: [email protected] *_/ ' \" =end
18+
* OpenAPI spec version: 1.0.0 */ ' " =end
19+
* Contact: [email protected] */ ' " =end
2020
* Generated by: https://github.com/swagger-api/swagger-codegen.git
2121
*
2222
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -102,7 +102,7 @@ class Configuration
102102
*
103103
* @var string
104104
*/
105-
protected $host = 'https://petstore.swagger.io *_/ &#39; \&quot; &#x3D;end/v2 *_/ &#39; \&quot; &#x3D;end';
105+
protected $host = 'https://petstore.swagger.io */ &#39; &quot; &#x3D;end/v2 */ &#39; &quot; &#x3D;end';
106106

107107
/**
108108
* Timeout (second) of the HTTP request, by default set to 0, no timeout
@@ -522,7 +522,7 @@ public static function toDebugReport()
522522
$report = 'PHP SDK (Swagger\Client) Debug Report:' . PHP_EOL;
523523
$report .= ' OS: ' . php_uname() . PHP_EOL;
524524
$report .= ' PHP Version: ' . phpversion() . PHP_EOL;
525-
$report .= ' OpenAPI Spec Version: 1.0.0 *_/ &#39; \&quot; &#x3D;end' . PHP_EOL;
525+
$report .= ' OpenAPI Spec Version: 1.0.0 */ &#39; &quot; &#x3D;end' . PHP_EOL;
526526
$report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL;
527527

528528
return $report;

samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
*/
1313

1414
/**
15-
* Swagger Petstore *_/ ' \" =end
15+
* Swagger Petstore */ ' " =end
1616
*
17-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end
17+
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end
1818
*
19-
* OpenAPI spec version: 1.0.0 *_/ ' \" =end
20-
* Contact: [email protected] *_/ ' \" =end
19+
* OpenAPI spec version: 1.0.0 */ ' " =end
20+
* Contact: [email protected] */ ' " =end
2121
* Generated by: https://github.com/swagger-api/swagger-codegen.git
2222
*
2323
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -47,7 +47,7 @@
4747
* ModelReturn Class Doc Comment
4848
*
4949
* @category Class */
50-
// @description Model for testing reserved words *_/ &#39; \&quot; &#x3D;end
50+
// @description Model for testing reserved words */ &#39; \&quot; &#x3D;end
5151
/**
5252
* @package Swagger\Client
5353
* @author http://github.com/swagger-api/swagger-codegen
@@ -167,7 +167,7 @@ public function getReturn()
167167

168168
/**
169169
* Sets return
170-
* @param int $return property description *_/ ' \" =end
170+
* @param int $return property description */ ' \" =end
171171
* @return $this
172172
*/
173173
public function setReturn($return)

0 commit comments

Comments
 (0)