forked from loafle/openapi-generator-original
Improve error message for connection failures
Previous ApiException message would simply print out the result of the `curl_getinfo($curl)` call, which might be useful only if the developer actually wanted very low-level information from curl about why a call failed. The new message should print out a higher-level but more informative, human-readable message. If necessary for debugging, the ApiException's responseObject is set to the `curl_getinfo($curl)`.
This commit is contained in:
@@ -224,7 +224,19 @@ class ApiClient
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
$curl_error_message = curl_error($curl);
|
||||
|
||||
// curl_exec can sometimes fail but still return a blank message from curl_error().
|
||||
if (!empty($curl_error_message)) {
|
||||
$error_message = "API call to $url failed: $curl_error_message";
|
||||
} else {
|
||||
$error_message = "API call to $url failed, but for an unknown reason. " .
|
||||
"This could happen if you are disconnected from the network.";
|
||||
}
|
||||
|
||||
$exception = new ApiException($error_message, 0, null, null);
|
||||
$exception->setResponseObject($response_info);
|
||||
throw $exception;
|
||||
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == '\SplFileObject' || $responseType == 'string') {
|
||||
|
||||
@@ -4,7 +4,7 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod
|
||||
This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
|
||||
|
||||
- API version: 1.0.0 */ ' " =end
|
||||
- Build date: 2016-07-06T12:08:58.407-07:00
|
||||
- Build date: 2016-07-06T12:09:22.895-07:00
|
||||
- Build package: class io.swagger.codegen.languages.PhpClientCodegen
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -245,7 +245,19 @@ class ApiClient
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
$curl_error_message = curl_error($curl);
|
||||
|
||||
// curl_exec can sometimes fail but still return a blank message from curl_error().
|
||||
if (!empty($curl_error_message)) {
|
||||
$error_message = "API call to $url failed: $curl_error_message";
|
||||
} else {
|
||||
$error_message = "API call to $url failed, but for an unknown reason. " .
|
||||
"This could happen if you are disconnected from the network.";
|
||||
}
|
||||
|
||||
$exception = new ApiException($error_message, 0, null, null);
|
||||
$exception->setResponseObject($response_info);
|
||||
throw $exception;
|
||||
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == '\SplFileObject' || $responseType == 'string') {
|
||||
|
||||
@@ -4,7 +4,7 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod
|
||||
This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
|
||||
|
||||
- API version: 1.0.0
|
||||
- Build date: 2016-07-06T12:01:52.156-07:00
|
||||
- Build date: 2016-07-06T12:05:01.729-07:00
|
||||
- Build package: class io.swagger.codegen.languages.PhpClientCodegen
|
||||
|
||||
## Requirements
|
||||
|
||||
@@ -245,7 +245,19 @@ class ApiClient
|
||||
|
||||
// Handle the response
|
||||
if ($response_info['http_code'] == 0) {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
$curl_error_message = curl_error($curl);
|
||||
|
||||
// curl_exec can sometimes fail but still return a blank message from curl_error().
|
||||
if (!empty($curl_error_message)) {
|
||||
$error_message = "API call to $url failed: $curl_error_message";
|
||||
} else {
|
||||
$error_message = "API call to $url failed, but for an unknown reason. " .
|
||||
"This could happen if you are disconnected from the network.";
|
||||
}
|
||||
|
||||
$exception = new ApiException($error_message, 0, null, null);
|
||||
$exception->setResponseObject($response_info);
|
||||
throw $exception;
|
||||
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == '\SplFileObject' || $responseType == 'string') {
|
||||
|
||||
Reference in New Issue
Block a user