diff --git a/composer.json b/composer.json index 8963ed5..e45f752 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,11 @@ "require": { "php": ">=7.2.5", "guzzlehttp/guzzle": "^6.3.1|^7.0", - "illuminate/support": "5.7.x|5.8.x|^6.0|^7.0", - "openfoodfacts/openfoodfacts-php": "^0.2.0" + "illuminate/support": "5.7.x|5.8.x|^6.0|^7.0|^8.0", + "openfoodfacts/openfoodfacts-php": "^0.2.3" }, "require-dev": { - "orchestra/testbench": "^3.7|4.*|5.*", + "orchestra/testbench": "^3.7|4.*|5.*|6.*", "phpunit/phpunit": "^7.5|^8.4|^9.0" }, "autoload": { diff --git a/src/OpenFoodFacts.php b/src/OpenFoodFacts.php index 2895888..59d012c 100644 --- a/src/OpenFoodFacts.php +++ b/src/OpenFoodFacts.php @@ -2,10 +2,10 @@ namespace OpenFoodFacts\Laravel; -use Illuminate\Contracts\Config\Repository; use Illuminate\Contracts\Container\Container; use Illuminate\Support\Collection; use InvalidArgumentException; +use OpenFoodFacts\Exception\ProductNotFoundException; class OpenFoodFacts extends OpenFoodFactsApiWrapper { @@ -27,9 +27,13 @@ public function barcode($value) throw new InvalidArgumentException("Argument must represent a barcode"); } - $doc = $this->api->getProduct($value); + try { + $doc = $this->api->getProduct($value); - return empty($doc->code) ? [] : reset($doc); + return empty($doc->code) ? [] : reset($doc); + } catch (ProductNotFoundException $notFoundException) { + return []; + } } public function find($searchterm)