Skip to content

Commit

Permalink
Fix typo in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
julienbourdeau committed Aug 16, 2018
1 parent 447dc7d commit d66c3c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/Http/Php53HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Algolia\AlgoliaSearch\Http;

use Algolia\AlgoliaSearch\Exceptions\BadRequestException;
use Algolia\AlgoliaSearch\Exceptions\NotFoundException;
use Algolia\AlgoliaSearch\Exceptions\RetriableException;
use Algolia\AlgoliaSearch\Http\Psr7\Request;
use Algolia\AlgoliaSearch\Http\Psr7\Uri;
Expand Down Expand Up @@ -37,7 +38,9 @@ public function createRequest(
$protocolVersion = '1.1'
) {
if (is_array($body)) {
$body = \json_encode($body);
// Send an empty body instead of "[]" in case there are
// no content/params to send
$body = empty($body) ? '' : \json_encode($body);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(
'json_encode error: '.json_last_error_msg());
Expand Down Expand Up @@ -156,7 +159,10 @@ public function sendRequest(RequestInterface $request, $timeout, $connectTimeout
throw new \Exception($statusCode.': Server responded with invalid Json response', $statusCode);
}

if (4 == intval($statusCode / 100)) {

if ($statusCode == 404) {
throw new NotFoundException($response['message'], $statusCode);
} elseif (4 == intval($statusCode / 100)) {
throw new BadRequestException(isset($response['message']) ? $response['message'] : $http_status.' error', $statusCode);
} elseif (2 != intval($statusCode / 100)) {
throw new \Exception($statusCode.': '.$response, $statusCode);
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testSettingsWithReplicas()
{
$replica1 = $this->safeName('settings-mgmt_REPLICA');
$index = static::getClient()->initIndex(static::$indexes['main']);
$replica = static::getClient()->initIndex(static::$indexes['replica1']);
$replica = static::getClient()->initIndex($replica1);

$settingsWithReplicas = array_merge($this->settings, array('replicas' => array($replica1)));

Expand Down

0 comments on commit d66c3c0

Please sign in to comment.