fix: make import command resilient to api errors

This commit is contained in:
Björn Fromme committed 2026-07-13 12:23:57 +02:00
1 parent 7f0223bbaa
commit b21de75b7f
3 files changed
+48 -21

No files matched your search

@@ -4,14 +4,19 @@ namespace App\BusProNet\DataProvider;
use App\BusProNet\ApiClient;
use App\BusProNet\ApiClientException;
use App\BusProNet\Model\NotificationResponse;
use App\BusProNet\Model\Pickup;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
class PickupDataProvider
{
public function __construct(private readonly ApiClient $apiClient, private readonly CacheInterface $cache)
{
public function __construct(
private readonly ApiClient $apiClient,
private readonly CacheInterface $cache,
private readonly LoggerInterface $logger,
) {
}
public function getAll(): array
@@ -20,11 +25,15 @@ class PickupDataProvider
$pickups = $this->cache->get('bpn_pickups', function (ItemInterface $item) {
$item->expiresAfter(3600);
return $this
->apiClient
->getBaseData(ApiClient::TYPE_BASE_DATA_PICKUPS)
->getItems()
;
$response = $this->apiClient->getBaseData(ApiClient::TYPE_BASE_DATA_PICKUPS);
if ($response instanceof NotificationResponse) {
$this->logger->error('Unable to fetch pickup base data from BusProNet. Code: '.$response->getCode().', Message: '.$response->getMessage());
throw new ApiClientException('Unable to fetch pickup base data from BusProNet');
}
return $response->getItems();
});
} catch (ApiClientException $e) {
$pickups = [];