Skip to content

Commit

Permalink
Fix doAuthenticatedRequest when response has no body (#2)
Browse files Browse the repository at this point in the history
* Fix doAuthenticatedRequest when response has no body
  • Loading branch information
j-ledoux authored and stephpy committed Feb 19, 2018
1 parent ca5c474 commit 1015436
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/REST/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ private function doAuthenticatedRequest(Request $request)
throw new SalesforceClientException($e->getMessage(), 0, $e);
}

return json_decode((string) $response->getBody(), true);
$body = '[]';

// Check if response has content
if ($response->getStatusCode() !== 204) {
$body = (string) $response->getBody();
}

return json_decode($body, true);
}

private function connectIfAccessTokenIsEmpty()
Expand Down
2 changes: 1 addition & 1 deletion tests/REST/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function test_create_object()

public function test_patch_object()
{
$sut = $this->createSUT(null, new Response(200));
$sut = $this->createSUT(null, new Response(204));
// we can't test the request since stream are different ...
// let's find a way to fix that.
$this->assertNull($sut->patchObject('foo', 1234, []));
Expand Down

0 comments on commit 1015436

Please sign in to comment.