Skip to content

Commit

Permalink
Throw exception for unsupported site
Browse files Browse the repository at this point in the history
  • Loading branch information
karlomikus committed Jan 6, 2025
1 parent 891fdfd commit 79c57be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v4.3.2
## Fixes
- Improve error handling when scraping recipes from unsupported sites

# v4.3.1
## Fixes
- CSV import now matches categories by case-insensitive name
Expand Down
8 changes: 7 additions & 1 deletion app/Scraper/AbstractSiteExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Kami\Cocktail\External\Model\IngredientBasic;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpClient\CachingHttpClient;
use Kami\Cocktail\Exceptions\ScraperMissingException;
use Symfony\Component\HttpClient\NoPrivateNetworkHttpClient;

abstract class AbstractSiteExtractor implements SiteExtractorContract
Expand Down Expand Up @@ -181,8 +182,13 @@ public function toArray(): array
$images[] = $image;
}

$name = $this->clean($this->name());
if (!$name) {
throw new ScraperMissingException('Unsupported site or no recipes found');
}

$cocktail = Cocktail::fromDraft2Array([
'name' => $this->clean($this->name()),
'name' => $name,
'instructions' => $this->instructions(),
'description' => $this->cleanDescription($this->description()),
'source' => $this->source(),
Expand Down
21 changes: 10 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 79c57be

Please sign in to comment.