Skip to content

Commit 29eceef

Browse files
authored
Merge pull request #20 from joeldodge79/drip-client-error-response
Test that a 400 or 500 response is not a success
2 parents 3154756 + b61c24a commit 29eceef

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ protected function make_request($url, $params = array(), $req_method = self::GET
337337
'Accept' => 'application/json, text/javascript, */*; q=0.01',
338338
'Content-Type' => 'application/vnd.api+json',
339339
],
340+
'http_errors' => false,
340341
];
341342

342343
switch ($req_method) {

tests/ClientTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ public function testInvalidAccountId()
2929
new \Drip\Client("abc123", "");
3030
}
3131

32+
public function testErrorResponseReturned()
33+
{
34+
$mocked_requests = [];
35+
$client = GuzzleHelpers::mocked_client($mocked_requests, [
36+
// default client request option "http_errors" will throw
37+
// GuzzleHttp\Exception\ClientException but we set it false so
38+
// no exception is thrown.
39+
new Response(401, [], '{"error":"hello"}'),
40+
new Response(502, [], 'timeout'),
41+
]);
42+
$response401 = $client->fetch_campaign(['campaign_id' => 1]);
43+
$this->assertFalse($response401->is_success());
44+
$response502 = $client->fetch_campaign(['campaign_id' => 1]);
45+
$this->assertFalse($response502->is_success());
46+
}
47+
3248
////////////////////////// C A M P A I G N S //////////////////////////
3349

3450
// #get_campaigns

0 commit comments

Comments
 (0)