From f6e955b487a13cda3192a283290a5e7827037568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sat, 22 Jun 2024 23:37:50 +0200 Subject: [PATCH] Hide mouser parts with an invalid product ID to avoid the issue described in #616 --- .../InfoProviderSystem/Providers/MouserProvider.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Services/InfoProviderSystem/Providers/MouserProvider.php b/src/Services/InfoProviderSystem/Providers/MouserProvider.php index e5f937da..84f5d65b 100644 --- a/src/Services/InfoProviderSystem/Providers/MouserProvider.php +++ b/src/Services/InfoProviderSystem/Providers/MouserProvider.php @@ -177,7 +177,7 @@ class MouserProvider implements InfoProviderInterface } if (count($tmp) > 1) { - throw new \RuntimeException('Multiple parts found with ID '.$id); + throw new \RuntimeException('Multiple parts found with ID '.$id . ' ('.count($tmp).' found). This is basically a bug in Mousers API response. See issue #616.'); } return $tmp[0]; @@ -211,6 +211,12 @@ class MouserProvider implements InfoProviderInterface $result = []; foreach ($products as $product) { + //Check if we have a valid product number. We assume that a product number, must have at least 4 characters + //Otherwise filter it out + if (strlen($product['MouserPartNumber']) < 4) { + continue; + } + //Check if we have a mass field available $mass = null; if (isset($product['UnitWeightKg']['UnitWeight'])) {