Skip to content

Commit

Permalink
Fix StructuredDataProvider Exception & empty image attachments
Browse files Browse the repository at this point in the history
For any URL, StructuredDataProvider caused an TypeError Exception
as soon as + ('Create new part') was clicked:
"App\Services\InfoProviderSystem\Providers\StructuredDataProvider::getResponse(): Argument Part-DB#1 ($url) must be of type string, null given, called in /var/www/partdb/src/Services/InfoProviderSystem/Providers/StructuredDataProvider.php on line 425" at /var/www/partdb/src/Services/InfoProviderSystem/Providers/StructuredDataProvider.php line 72
  • Loading branch information
jyevon committed Aug 31, 2023
1 parent 9273928 commit 90587ac
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ protected function productToDTO(Schema\Product $product,
//Parse images
$images = [];
foreach($product->image as $image) {
if(empty($image)) continue;

$images[] = new FileDTO((string) $image);
}
$preview = $images[0]->url ?? null;
Expand Down Expand Up @@ -422,7 +424,7 @@ public function getDetails(string $id): PartDetailDTO

$siteOwner = null;
$breadcrumbs = null;
$products = $this->getSchemaProducts($this->getResponse($tmp), $url, $siteOwner, $breadcrumbs);
$products = $this->getSchemaProducts($this->getResponse($url), $url, $siteOwner, $breadcrumbs);
if(count($products) == 0)
throw new \Exception("parse error: product page doesn't contain a https://schema.org/Product");
// TODO : Find a better way to inform the user / log for debugging (here a faulty URLs is the user's fault)
Expand Down

0 comments on commit 90587ac

Please sign in to comment.