@@ -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