Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Exception message contains JSON and string data. #23

@rquadling

Description

@rquadling

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions