Skip to content

No HTTP errors handling #7

Description

@sergeolkhovik

I've got a problem with SSL CA but this library didn't catch that and kept returning empty string.
This isn't good, I think the library should check HTTP response code. I updated code a little, please review the following patch:

% cat sendgrid.patch 
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: libraries/SendGrid-PHP-Library/sendgrid/core
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: sendgrid-connect.php
--- sendgrid-connect.php Base (BASE)
+++ sendgrid-connect.php Locally Modified (Based On LOCAL)
@@ -55,7 +55,7 @@
     * sendgrid endpoint ...
     * @var string
     */
-   const SG_ENDPOINT = 'https://sendgrid.com/api';
+   const SG_ENDPOINT = 'https://api.sendgrid.com/api';
 
    /**
     * Creates a new SendGrid Newsletter API object to make calls with
@@ -119,8 +119,10 @@
 
        // obtain response
        $jsonResponse = curl_exec($session);
-       curl_close($session);
-       
+       $http_code = curl_getinfo($session, CURLINFO_HTTP_CODE);
+       if ($http_code != 200) {
+           $this->lastResponseError = curl_error($session);
+       } else {
        $this->debugCall('DEBUG - Json Response: ' , $jsonResponse);
        
        $results  = json_decode ( $jsonResponse, TRUE );
@@ -128,6 +130,8 @@
        $this->debugCall('DEBUG - Results: ' , $results);
        
        $this->lastResponseError = isset($results['error']) ? $results['error'] : NULL;
+        }
+       curl_close($session);
 
        return $this->lastResponseError ? false : $results;
    }

Also please note that SG API has new URL.

PS: after these changes I finally found a reason why my stopped communicating with SG: "Problem with the SSL CA cert (path? access rights?)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions