gocardless-legacy-php icon indicating copy to clipboard operation
gocardless-legacy-php copied to clipboard

Exception message contains JSON and string data.

Open rquadling opened this issue 11 years ago • 0 comments

Hi.

Just testing the exceptions that can be generated by the API. Getting a pre-auth with the wrong credentials setup results in a JSON encoded error, with a couple of blocks of curl error information.

It would be nice to have the whole lot as JSON.

I'm not sure of all the touch points for through the exceptions, but the following is the replacement I'm using.

diff --git a/includes/frontend/site_includes/classes/GoCardless/Request.php b/includes/frontend/site_includes/classes/GoCardless/Request.php
index c729764..9a57b43 100644
--- a/includes/frontend/site_includes/classes/GoCardless/Request.php
+++ b/includes/frontend/site_includes/classes/GoCardless/Request.php
@@ -193,7 +193,14 @@ class GoCardless_Request {
       $message = //print_r(json_decode($result, true), true); // Original line.
           'Curl result : ' . var_export($result, true) . PHP_EOL .
           'curl_get_info ' . var_export(curl_getinfo($ch), True) . PHP_EOL .
-          'curl_error : ('. curl_errno($ch) .') ' . curl_error($ch); 
+          'curl_error : ('. curl_errno($ch) .') ' . curl_error($ch);
+      
+      $message = json_encode(array(
+        'Curl_result'   => json_decode($result),
+        'curl_get_info' => curl_getinfo($ch),
+        'curl_errno'    => curl_errno($ch),
+        'curl_error'    => curl_error($ch),
+      ));

       // Throw an exception with the error message
       throw new GoCardless_ApiException($message, $http_response_code);

The path and index entries may not tie up to yours. This is the tail end of the GoCardless_Request::call() method.

rquadling avatar Jul 08 '13 08:07 rquadling