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);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ final class BulkInfoProviderService
|
|||
}
|
||||
|
||||
$partResults = [];
|
||||
$hasAnyResults = false;
|
||||
|
||||
// Group providers by batch capability
|
||||
$batchProviders = [];
|
||||
|
|
@ -88,7 +87,6 @@ final class BulkInfoProviderService
|
|||
);
|
||||
|
||||
if (!empty($allResults)) {
|
||||
$hasAnyResults = true;
|
||||
$searchResults = $this->formatSearchResults($allResults);
|
||||
}
|
||||
|
||||
|
|
@ -99,10 +97,6 @@ final class BulkInfoProviderService
|
|||
);
|
||||
}
|
||||
|
||||
if (!$hasAnyResults) {
|
||||
throw new \RuntimeException('No search results found for any of the selected parts');
|
||||
}
|
||||
|
||||
$response = new BulkSearchResponseDTO($partResults);
|
||||
|
||||
// Prefetch details if requested
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue