Skip to content

Commit 7275db2

Browse files
committed
Manually filter mouser search results to fix the edgecase, that the API returned multiple results for an exact part number
This fixes issue #888 and issue #616
1 parent 49ee913 commit 7275db2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Services/InfoProviderSystem/Providers/MouserProvider.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public function searchByKeyword(string $keyword): array
9494
From the startingRecord, the number of records specified will be returned up to the end of the recordset.
9595
This is useful for paging through the complete recordset of parts matching keyword.
9696
97+
9798
searchOptions string
9899
Optional.
99100
If not provided, the default is None.
@@ -176,11 +177,16 @@ public function getDetails(string $id): PartDetailDTO
176177
throw new \RuntimeException('No part found with ID '.$id);
177178
}
178179

180+
//Manually filter out the part with the correct ID
181+
$tmp = array_filter($tmp, fn(PartDetailDTO $part) => $part->provider_id === $id);
182+
if (count($tmp) === 0) {
183+
throw new \RuntimeException('No part found with ID '.$id);
184+
}
179185
if (count($tmp) > 1) {
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.');
186+
throw new \RuntimeException('Multiple parts found with ID '.$id);
181187
}
182188

183-
return $tmp[0];
189+
return reset($tmp);
184190
}
185191

186192
public function getCapabilities(): array

0 commit comments

Comments
 (0)