feat: improved error handling and feedback
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\BusProNet\Security;
|
|||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
use App\BusProNet\Exception\ApiClientException;
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
use App\BusProNet\Model\CrmAttributes;
|
use App\BusProNet\Model\CrmAttributes;
|
||||||
use App\BusProNet\Model\PersonalData;
|
use App\BusProNet\Model\PersonalData;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -45,7 +46,7 @@ class Authenticator extends AbstractLoginFormAuthenticator implements Authentica
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->getPersonalData($email, $password);
|
$response = $this->apiClient->getPersonalData($email, $password);
|
||||||
} catch (ApiClientException $e) {
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
throw new CustomUserMessageAuthenticationException($e->getMessage());
|
throw new CustomUserMessageAuthenticationException($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Controller\Booking;
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
use App\BusProNet\Model\Notification;
|
use App\BusProNet\Model\Notification;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@@ -56,13 +58,16 @@ class DownloadController extends AbstractController
|
|||||||
'booking_id' => $id,
|
'booking_id' => $id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
$file = $this
|
$file = $this
|
||||||
->apiClient
|
->apiClient
|
||||||
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type)
|
->getDocuments($bpnUser->getEmail(), $bpnUser->getPassword(), $id, $type);
|
||||||
;
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
|
$file = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $file || $file instanceof Notification) {
|
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');
|
return $this->redirectToRoute('app_bookings');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
namespace App\Controller\Booking;
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
use App\BusProNet\Model\Notification;
|
use App\BusProNet\Model\Notification;
|
||||||
use App\BusProNet\XmlLoader\PickupLoader;
|
use App\BusProNet\XmlLoader\PickupLoader;
|
||||||
use App\BusProNet\XmlLoader\TravelLoader;
|
use App\BusProNet\XmlLoader\TravelLoader;
|
||||||
@@ -69,10 +71,22 @@ class EditController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch mutability information via API
|
// Fetch mutability information via API
|
||||||
|
try {
|
||||||
$mutableData = $this->apiClient->getMutableData($bookingData->travelId);
|
$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
|
// Fetch availability information via API
|
||||||
|
try {
|
||||||
$availabilities = $this->apiClient->getAvailabilities($bookingData->travelId);
|
$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
|
// Patch travel data with additional information from above
|
||||||
$this->travelDataLoader->patchAvailabilities($travelData, $availabilities);
|
$this->travelDataLoader->patchAvailabilities($travelData, $availabilities);
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
namespace App\Controller\Booking;
|
namespace App\Controller\Booking;
|
||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
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 App\BusProNet\XmlLoader\TravelLoader;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
@@ -30,7 +33,12 @@ class IndexController extends AbstractController
|
|||||||
return $this->security->logout();
|
return $this->security->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$bookings = $this->apiClient->getBookings($bpnUser->getEmail(), $bpnUser->getPassword());
|
$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);
|
$this->travelDataLoader->patchBookings($bookings);
|
||||||
|
|
||||||
return $this->render('booking/index.html.twig', [
|
return $this->render('booking/index.html.twig', [
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
use App\BusProNet\Exception\ApiClientException;
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
|
use App\BusProNet\Model\PersonalData;
|
||||||
use App\Form\PersonalDataType;
|
use App\Form\PersonalDataType;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
@@ -32,10 +34,14 @@ class PersonalDataController extends AbstractController
|
|||||||
return $this->security->logout();
|
return $this->security->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$personalData = $this
|
$personalData = $this
|
||||||
->apiClient
|
->apiClient
|
||||||
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword())
|
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||||
;
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
|
$this->addFlash('error', 'Deine persönlichen Daten konnten nicht abgerufen werden');
|
||||||
|
$personalData = new PersonalData();
|
||||||
|
}
|
||||||
|
|
||||||
$personalDataForm = $this->createForm(PersonalDataType::class, $personalData, [
|
$personalDataForm = $this->createForm(PersonalDataType::class, $personalData, [
|
||||||
'attr' => ['novalidate' => 'novalidate'],
|
'attr' => ['novalidate' => 'novalidate'],
|
||||||
@@ -72,10 +78,14 @@ class PersonalDataController extends AbstractController
|
|||||||
return $this->security->logout();
|
return $this->security->logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$personalData = $this
|
$personalData = $this
|
||||||
->apiClient
|
->apiClient
|
||||||
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword())
|
->getPersonalData($bpnUser->getEmail(), $bpnUser->getPassword());
|
||||||
;
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
|
$this->addFlash('error', 'Deine persönlichen Daten konnten nicht abgerufen werden');
|
||||||
|
$personalData = new PersonalData();
|
||||||
|
}
|
||||||
|
|
||||||
$personalData->communication->newsletter = !$personalData->communication->newsletter;
|
$personalData->communication->newsletter = !$personalData->communication->newsletter;
|
||||||
|
|
||||||
@@ -85,7 +95,7 @@ class PersonalDataController extends AbstractController
|
|||||||
$this->logger->info('Updated newsletter registration', [
|
$this->logger->info('Updated newsletter registration', [
|
||||||
'email' => $bpnUser->getEmail(),
|
'email' => $bpnUser->getEmail(),
|
||||||
]);
|
]);
|
||||||
} catch (ApiClientException $e) {
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
$this->addFlash('error', $e->getMessage());
|
$this->addFlash('error', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
use App\BusProNet\Exception\ApiClientException;
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
use App\Form\Model\RegistrationData;
|
use App\Form\Model\RegistrationData;
|
||||||
use App\Form\RegistrationType;
|
use App\Form\RegistrationType;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -42,7 +43,7 @@ class RegistrationController extends AbstractController
|
|||||||
$this->logger->info('Initiated registration', [
|
$this->logger->info('Initiated registration', [
|
||||||
'email' => $registrationData->email,
|
'email' => $registrationData->email,
|
||||||
]);
|
]);
|
||||||
} catch (ApiClientException $e) {
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
$this->addFlash('error', $e->getMessage());
|
$this->addFlash('error', $e->getMessage());
|
||||||
$this->logger->error('Error initiating registration', [
|
$this->logger->error('Error initiating registration', [
|
||||||
'email' => $registrationData->email,
|
'email' => $registrationData->email,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Controller;
|
|||||||
|
|
||||||
use App\BusProNet\ApiClient;
|
use App\BusProNet\ApiClient;
|
||||||
use App\BusProNet\Exception\ApiClientException;
|
use App\BusProNet\Exception\ApiClientException;
|
||||||
|
use App\BusProNet\Exception\ResponseParserException;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
@@ -51,7 +52,7 @@ class ResetPasswordController extends AbstractController
|
|||||||
$this->logger->info('Initiated password reset', [
|
$this->logger->info('Initiated password reset', [
|
||||||
'email' => $form->get('email')->getData(),
|
'email' => $form->get('email')->getData(),
|
||||||
]);
|
]);
|
||||||
} catch (ApiClientException $e) {
|
} catch (ApiClientException|ResponseParserException $e) {
|
||||||
$this->addFlash('error', $e->getMessage());
|
$this->addFlash('error', $e->getMessage());
|
||||||
$this->logger->error('Error initiating password reset', [
|
$this->logger->error('Error initiating password reset', [
|
||||||
'email' => $form->get('email')->getData(),
|
'email' => $form->get('email')->getData(),
|
||||||
|
|||||||
Reference in New Issue
Block a user