Skip to content

Commit

Permalink
Merge pull request #9 from answear/handle-empty-response-in-detectByF…
Browse files Browse the repository at this point in the history
…eature

Handle empty response in SearchByFeature
  • Loading branch information
jrawska authored Nov 30, 2021
2 parents c0b8021 + ea7535d commit f35552f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Response/SearchByFeatureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ private function __construct(array $uids)

public static function fromArray(array $response): SearchByFeatureResponse
{
if (!isset($response[0]['products']) || !is_array($response[0]['products'])) {
throw new MalformedResponse('Empty result', $response);
}

try {
$products = $response[0]['products'];
$responseUids = array_map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function responseWithoutProducts(): void
$this->guzzleHandler->append(new Response(200, [], $this->prepareNotProperResponse()));

$this->expectException(MalformedResponse::class);
$this->expectExceptionMessage('Undefined index: products');
$this->expectExceptionMessage('Empty result');

$this->client->searchByFeature(self::FEATURE_ID, self::LABEL);
}
Expand Down

0 comments on commit f35552f

Please sign in to comment.