feat: improved error handling

This commit is contained in:
Björn Fromme
2025-04-01 09:27:40 +02:00
parent 158f5ac51f
commit 336e258c86
2 changed files with 25 additions and 0 deletions
@@ -5,7 +5,9 @@ namespace App\Controller\Booking;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\BaseData;
use App\BusProNet\Model\Notification;
use App\BusProNet\XmlLoader\TravelLoader;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
@@ -19,6 +21,7 @@ class IndexController extends AbstractController
private readonly ApiClient $apiClient,
private readonly TravelLoader $travelDataLoader,
private readonly Security $security,
private readonly LoggerInterface $logger,
) {
}
@@ -38,6 +41,17 @@ class IndexController extends AbstractController
$this->addFlash('error', 'Buchungen nicht abrufbar');
$bookings = new BaseData([]);
}
if ($bookings instanceof Notification) {
$this->logger->error('Unable to fetch bookings data', [
'code' => $bookings->code,
'error' => $bookings->message,
]);
$this->addFlash('error', 'Buchungen nicht abrufbar');
$bookings = new BaseData([]);
}
$this->travelDataLoader->patchBookings($bookings);
return $this->render('booking/index.html.twig', [
+11
View File
@@ -4,6 +4,7 @@ namespace App\Controller;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\Notification;
use App\BusProNet\Model\PersonalData;
use App\Form\PersonalDataType;
use Psr\Log\LoggerInterface;
@@ -42,6 +43,16 @@ class PersonalDataController extends AbstractController
$personalData = new PersonalData();
}
if ($personalData instanceof Notification) {
$this->logger->error('Unable to fetch personal data', [
'code' => $personalData->code,
'error' => $personalData->message,
]);
$this->addFlash('error', 'Deine persönlichen Daten konnten nicht abgerufen werden');
$personalData = new PersonalData();
}
$personalDataForm = $this->createForm(PersonalDataType::class, $personalData, [
'attr' => ['novalidate' => 'novalidate'],
]);