mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-11 07:22:12 +00:00
Fix 500 error when field mapping has null field or no search results
- Skip field mappings with null/empty field values in convertFieldMappingsToDto - Return empty DTO instead of throwing when no search results found - Remove unnecessary try/catch workaround in researchPart
This commit is contained in:
parent
11c2780383
commit
0b6fc7bfa0
2 changed files with 5 additions and 16 deletions
|
|
@ -68,6 +68,10 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
{
|
||||
$dtos = [];
|
||||
foreach ($fieldMappings as $mapping) {
|
||||
// Skip entries where field is null/empty (e.g. user added a row but didn't select a field)
|
||||
if (empty($mapping['field'])) {
|
||||
continue;
|
||||
}
|
||||
$dtos[] = new BulkSearchFieldMappingDTO(field: $mapping['field'], providers: $mapping['providers'], priority: $mapping['priority'] ?? 1);
|
||||
}
|
||||
return $dtos;
|
||||
|
|
@ -472,16 +476,7 @@ class BulkInfoProviderImportController extends AbstractController
|
|||
$fieldMappingDtos = $job->getFieldMappings();
|
||||
$prefetchDetails = $job->isPrefetchDetails();
|
||||
|
||||
try {
|
||||
$searchResultsDto = $this->bulkService->performBulkSearch([$part], $fieldMappingDtos, $prefetchDetails);
|
||||
} catch (\Exception $searchException) {
|
||||
// Handle "no search results found" as a normal case, not an error
|
||||
if (str_contains($searchException->getMessage(), 'No search results found')) {
|
||||
$searchResultsDto = null;
|
||||
} else {
|
||||
throw $searchException;
|
||||
}
|
||||
}
|
||||
$searchResultsDto = $this->bulkService->performBulkSearch([$part], $fieldMappingDtos, $prefetchDetails);
|
||||
|
||||
// Update the job's search results for this specific part efficiently
|
||||
$this->updatePartSearchResults($job, $searchResultsDto[0] ?? null);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue