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([]);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Controller;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\ResponseParserException;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Form\PersonalDataType;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -38,7 +37,7 @@ class PersonalDataController extends AbstractController
|
||||
$personalData = $this
|
||||
->apiClient
|
||||
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Deine persönlichen Daten konnten nicht abgerufen werden');
|
||||
$personalData = new PersonalData();
|
||||
}
|
||||
@@ -82,7 +81,7 @@ class PersonalDataController extends AbstractController
|
||||
$personalData = $this
|
||||
->apiClient
|
||||
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', 'Deine persönlichen Daten konnten nicht abgerufen werden');
|
||||
$personalData = new PersonalData();
|
||||
}
|
||||
@@ -95,7 +94,7 @@ class PersonalDataController extends AbstractController
|
||||
$this->logger->info('Updated newsletter registration', [
|
||||
'email' => $bpnUser->getEmail(),
|
||||
]);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Controller;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\ResponseParserException;
|
||||
use App\Form\Model\RegistrationData;
|
||||
use App\Form\RegistrationType;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -43,7 +42,7 @@ class RegistrationController extends AbstractController
|
||||
$this->logger->info('Initiated registration', [
|
||||
'email' => $registrationData->email,
|
||||
]);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
$this->logger->error('Error initiating registration', [
|
||||
'email' => $registrationData->email,
|
||||
|
||||
@@ -52,7 +52,7 @@ class ResetPasswordController extends AbstractController
|
||||
$this->logger->info('Initiated password reset', [
|
||||
'email' => $form->get('email')->getData(),
|
||||
]);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
$this->addFlash('error', $e->getMessage());
|
||||
$this->logger->error('Error initiating password reset', [
|
||||
'email' => $form->get('email')->getData(),
|
||||
|
||||
Reference in New Issue
Block a user