feat: improved error handling and feedback

This commit is contained in:
Björn Fromme
2025-03-24 19:41:51 +01:00
parent 7bcda3e6f8
commit 296464701d
7 changed files with 64 additions and 24 deletions
+11 -6
View File
@@ -3,6 +3,8 @@
namespace App\Controller\Booking;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Exception\ResponseParserException;
use App\BusProNet\Model\Notification;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -56,13 +58,16 @@ class DownloadController extends AbstractController
'booking_id' => $id,
]);
$file = $this
->apiClient
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type)
;
try {
$file = $this
->apiClient
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type);
} catch (ApiClientException|ResponseParserException $e) {
$file = null;
}
if (null === $file || $file instanceof Notification) {
$this->addFlash('error', 'Keine Dokumente vorhanden');
$this->addFlash('error', 'Keine Dokumente vorhanden oder nicht abrufbar');
return $this->redirectToRoute('app_bookings');
}
@@ -84,4 +89,4 @@ class DownloadController extends AbstractController
return $response;
}
}
}
+16 -2
View File
@@ -3,6 +3,8 @@
namespace App\Controller\Booking;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Exception\ResponseParserException;
use App\BusProNet\Model\Notification;
use App\BusProNet\XmlLoader\PickupLoader;
use App\BusProNet\XmlLoader\TravelLoader;
@@ -69,10 +71,22 @@ class EditController extends AbstractController
}
// Fetch mutability information via API
$mutableData = $this->apiClient->getMutableData($bookingData->travelId);
try {
$mutableData = $this->apiClient->getMutableData($bookingData->travelId);
} catch (ApiClientException|ResponseParserException $e) {
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
return $this->redirectToRoute('app_bookings');
}
// Fetch availability information via API
$availabilities = $this->apiClient->getAvailabilities($bookingData->travelId);
try {
$availabilities = $this->apiClient->getAvailabilities($bookingData->travelId);
} catch (ApiClientException|ResponseParserException $e) {
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
return $this->redirectToRoute('app_bookings');
}
// Patch travel data with additional information from above
$this->travelDataLoader->patchAvailabilities($travelData, $availabilities);
+10 -2
View File
@@ -3,6 +3,9 @@
namespace App\Controller\Booking;
use App\BusProNet\ApiClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Exception\ResponseParserException;
use App\BusProNet\Model\BaseData;
use App\BusProNet\XmlLoader\TravelLoader;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
@@ -30,11 +33,16 @@ class IndexController extends AbstractController
return $this->security->logout();
}
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
try {
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
} catch (ApiClientException|ResponseParserException $e) {
$this->addFlash('error', 'Buchungen nicht abrufbar');
$bookings = new BaseData([]);
}
$this->travelDataLoader->patchBookings($bookings);
return $this->render('booking/index.html.twig', [
'bookings' => $bookings->getItems(),
]);
}
}
}