Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit 07e4399

Browse files
Merge remote-tracking branch 'origin/curl-errors'
2 parents bb94e6a + 9c19f55 commit 07e4399

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

lib/BFPHPClient/BillForwardClient.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class Bf_RawAPIOutput {
77
* @param mixed $info
88
* @param RestAPIResponse $response
99
*/
10-
public function __construct($info, $response) {
10+
public function __construct($info, $response, $error) {
1111
$this->info = $info;
1212
$this->response = $response;
13+
$this->error = $error;
1314
}
1415

1516
/**
@@ -30,6 +31,10 @@ public function getInfo() {
3031
return $this->info;
3132
}
3233

34+
public function getCurlError() {
35+
return $this->error;
36+
}
37+
3338
public function getResults() {
3439
$json = $this->payloadArray();
3540
$results = $json['results'];
@@ -106,13 +111,32 @@ protected static function handleError($response) {
106111

107112
//if ($info['http_code'] != 200) {
108113
if (is_null($payloadArray)) {
109-
if (is_null($payloadStr)) {
114+
if (is_null($payloadStr) || $payloadStr === false) {
110115
// I think this means you cannot connect to API.
111-
$errorString = sprintf("\n====\nNo message returned by API.\nHTTP code: \t<%d>\n====", $httpCode);
116+
$errorString = sprintf(
117+
"\n====\nNo message returned by API.\nHTTP code: \t<%d>\n%s====",
118+
$httpCode,
119+
$response->getCurlError()
120+
? sprintf(
121+
"cURL error: \t<%s>\n",
122+
$response->getCurlError()
123+
)
124+
: ''
125+
);
112126
throw new Bf_NoAPIResponseException($errorString, $httpCode, NULL);
113127
} else {
114128
// I think this means you can connect to API, but it is in a bad state.
115-
$errorString = sprintf("\n====\nNo message returned by API.\nHTTP code: \t<%d>\nRaw response: \t<%s>\n====", $httpCode, $payloadStr);
129+
$errorString = sprintf(
130+
"\n====\nNo message returned by API.\nHTTP code: \t<%d>\nRaw response: \t<%s>\n%s====",
131+
$httpCode,
132+
$payloadStr,
133+
$response->getCurlError()
134+
? sprintf(
135+
"cURL error: \t<%s>\n",
136+
$response->getCurlError()
137+
)
138+
: ''
139+
);
116140
throw new Bf_NoAPIResponseException(
117141
$errorString,
118142
$httpCode,
@@ -311,8 +335,12 @@ private function doCurl(
311335

312336
$response = curl_exec($curl);
313337
$info = curl_getinfo($curl);
338+
$error = $info === false
339+
? curl_error($curl)
340+
: NULL;
341+
314342
curl_close($curl);
315343

316-
return new Bf_RawAPIOutput($info, $response);
344+
return new Bf_RawAPIOutput($info, $response, $error);
317345
}
318346
}

0 commit comments

Comments
 (0)