Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/MailChimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = se

$response['headers'] = curl_getinfo($ch);
if ($responseContent === false) {
$this->last_error = curl_error($ch);
$this->last_error = "Curl Error: " . curl_error($ch);
$formattedResponse = false;
} else {
$headerSize = $response['headers']['header_size'];

Expand All @@ -259,14 +260,16 @@ private function makeRequest($http_verb, $method, $args = array(), $timeout = se
if (isset($response['headers']['request_header'])) {
$this->last_request['headers'] = $response['headers']['request_header'];
}

$formattedResponse = $this->formatResponse($response);

$this->determineSuccess($response, $formattedResponse, $timeout);
}

$this->last_response = $response;

curl_close($ch);

$formattedResponse = $this->formatResponse($response);

$this->determineSuccess($response, $formattedResponse, $timeout);

return $formattedResponse;
}

Expand Down Expand Up @@ -360,8 +363,6 @@ private function attachRequestPayload(&$ch, $data)
*/
private function formatResponse($response)
{
$this->last_response = $response;

if (!empty($response['body'])) {
return json_decode($response['body'], true);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/MailChimpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,17 @@ public function testRequestTimeout()
$error = $MailChimp->getLastError();
$this->assertRegExp( '/Request timed out after 1.\d+ seconds/', $error );
}

public function testCurlErrorPassthrough()
{
$badDataCenter = 'us999999999';

$MailChimp = new MailChimp("abc123-$badDataCenter");

$MailChimp->get('lists');

// Ensure that the curl error is not overwritten and makes it back to the user.
// If this assertion passes, other curl errors should make it back to the user as well.
$this->assertEquals("Curl Error: Couldn't resolve host '$badDataCenter.api.mailchimp.com'", $MailChimp->getLastError());
}
}