feat: improved exception handling
This commit is contained in:
@@ -4,7 +4,6 @@ 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;
|
||||
@@ -62,7 +61,7 @@ class DownloadController extends AbstractController
|
||||
$file = $this
|
||||
->apiClient
|
||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$file = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ class EditController extends AbstractController
|
||||
// Fetch mutability information via API
|
||||
try {
|
||||
$mutableData = $this->apiClient->getMutableData($bookingData->travelId);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
@@ -82,7 +82,7 @@ class EditController extends AbstractController
|
||||
// Fetch availability information via API
|
||||
try {
|
||||
$availabilities = $this->apiClient->getAvailabilities($bookingData->travelId);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Reisedaten nicht (mehr) verfügbar');
|
||||
|
||||
return $this->redirectToRoute('app_bookings');
|
||||
@@ -103,36 +103,41 @@ class EditController extends AbstractController
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$response = $this->apiClient->updateBooking($formData, true);
|
||||
$this->logger->info('Initiated booking update', [
|
||||
'email' => $bpnUser->getEmail(),
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
if ($response instanceof Notification) {
|
||||
if (true === $response->isError()) {
|
||||
$this->addFlash('error', $response->message);
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->updateBooking($formData, true);
|
||||
if ($response instanceof Notification) {
|
||||
if (true === $response->isError()) {
|
||||
$this->addFlash('error', $response->message);
|
||||
} else {
|
||||
$this->addFlash('info', $response->message);
|
||||
}
|
||||
$this->logger->error('Booking update not successful', [
|
||||
'email' => $bpnUser->getEmail(),
|
||||
'booking_id' => $id,
|
||||
'message' => $response->message,
|
||||
]);
|
||||
} else {
|
||||
$this->addFlash('info', $response->message);
|
||||
try {
|
||||
$this->cache->delete($cacheKey);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
}
|
||||
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
|
||||
$this->logger->info('Booking update successful', [
|
||||
'email' => $bpnUser->getEmail(),
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
}
|
||||
$this->logger->error('Booking update not successful', [
|
||||
'email' => $bpnUser->getEmail(),
|
||||
'booking_id' => $id,
|
||||
'message' => $response->message,
|
||||
]);
|
||||
} else {
|
||||
try {
|
||||
$this->cache->delete($cacheKey);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
}
|
||||
|
||||
$this->addFlash('success', 'Buchung erfolgreich aktualisiert');
|
||||
|
||||
$this->logger->info('Booking update successful', [
|
||||
'email' => $bpnUser->getEmail(),
|
||||
'booking_id' => $id,
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_booking_edit', ['id' => $id]);
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Es ist ein Fehler in der Kommunikation mit dem Buchungssystem aufgetreten');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ 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;
|
||||
@@ -35,7 +34,7 @@ class IndexController extends AbstractController
|
||||
|
||||
try {
|
||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Buchungen nicht abrufbar');
|
||||
$bookings = new BaseData([]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user