Skip to content

Commit f6e955b

Browse files
committed
Hide mouser parts with an invalid product ID to avoid the issue described in #616
1 parent 32a72bf commit f6e955b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Services/InfoProviderSystem/Providers/MouserProvider.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function getDetails(string $id): PartDetailDTO
177177
}
178178

179179
if (count($tmp) > 1) {
180-
throw new \RuntimeException('Multiple parts found with ID '.$id);
180+
throw new \RuntimeException('Multiple parts found with ID '.$id . ' ('.count($tmp).' found). This is basically a bug in Mousers API response. See issue #616.');
181181
}
182182

183183
return $tmp[0];
@@ -211,6 +211,12 @@ private function responseToDTOArray(ResponseInterface $response): array
211211
$result = [];
212212
foreach ($products as $product) {
213213

214+
//Check if we have a valid product number. We assume that a product number, must have at least 4 characters
215+
//Otherwise filter it out
216+
if (strlen($product['MouserPartNumber']) < 4) {
217+
continue;
218+
}
219+
214220
//Check if we have a mass field available
215221
$mass = null;
216222
if (isset($product['UnitWeightKg']['UnitWeight'])) {

0 commit comments

Comments
 (0)